Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是什么导致了这个错误的请求?_Python_Flask - Fatal编程技术网

Python 是什么导致了这个错误的请求?

Python 是什么导致了这个错误的请求?,python,flask,Python,Flask,我的烧瓶应用程序视图功能: @app.route("/database_filter", methods=['POST', 'GET']) def database_filter(): error = '' points = '' time_search = False hdop_search = False points_len = 0 conn = sqlite3.connect(database) c = conn.cursor()

我的烧瓶应用程序视图功能:

@app.route("/database_filter", methods=['POST', 'GET'])
def database_filter():

    error = ''
    points = ''
    time_search = False
    hdop_search = False
    points_len = 0
    conn = sqlite3.connect(database)
    c = conn.cursor()

    if request.method == 'POST':

        '''If all datetime forms are filled out and the start is not after the end, set time_search True'''

        if request.form['startdate'] and \
            request.form['starttime'] and \
            request.form['enddate'] and \
            request.form['endtime']:
            start = request.form['startdate'] + 'T' + request.form['starttime']
            end = request.form['enddate'] + 'T' + request.form['endtime']
            if datetime_object(start) > datetime_object(end):
                error = '**Start value selected must occur before End value.'
                return render_template('database_filter.html', error=error)
            else:
                time_search = True
                print 'time search: ' + str(time_search)

        if request.form['hdop_oper'] and request.form['hdop']:
            hdop_search = True
            print 'hdop and hdop_oper exist'
            hdop_oper = request.form['hdop_oper']
            hdop = float(request.form['hdop'])


        '''Prepare search statement based on forms selected'''

        if time_search == True and hdop_search == True:
            print 'Time and hdop:'
            search_string = 'SELECT * from (SELECT TSTAMP, LAT, LON, FILE, HDOP FROM POINTS WHERE TSTAMP BETWEEN "%s" and "%s") WHERE HDOP %s %.1f ORDER BY TSTAMP DESC'%(start, end, hdop_oper, hdop)
            print search_string

        if time_search == False and hdop_search == True:
            print 'Hdop only'
            search_string = 'SELECT TSTAMP, LAT, LON, FILE, HDOP FROM POINTS WHERE HDOP %s %.1f ORDER BY TSTAMP DESC'%(hdop_oper, hdop)
            print search_string

        if time_search == True and hdop_search == False:
            print 'Time only'
            search_string = 'SELECT TSTAMP, LAT, LON, FILE FROM POINTS WHERE TSTAMP BETWEEN "%s" and "%s" ORDER BY TSTAMP DESC'%(start, end)
            print search_string

        if time_search == False and hdop_search == False:
            print 'no time no hdop'
            error = 'No search criteria selected.'
            search_string = 'SELECT TSTAMP, LAT, LON, FILE FROM POINTS ORDER BY TSTAMP DESC'
            print search_string

        '''Execute SQL search and return dictionary of points'''

        cur = c.execute(search_string)

        points = [dict(TSTAMP=row[0][11:20], DATE=row[0][0:10],
            LAT=row[1],
            LON=row[2],
            FILE = row[3]) for row in cur.fetchall()]

        points_len = len(points)

        return render_template('database_filter.html', error=error, points=points, points_len=points_len)

    return render_template('database_filter.html', error=error, points=points, points_len=points_len)
以及要呈现它的html页面:

<!--Filter Search criteria form -->
<form action="database_filter" id="database_filter" method="post">
    <p id="basicExample">
        <!-- Date/time range form; requires js library at bottom -->
        <input type="test" placeholder="Start Date" class="date start" name="startdate" value="{{ request.form.startdate }}">
        <input type="test" placeholder="Start Time" class="time start" name="starttime" value="{{ request.form.starttime }}">  to  
        <input type="test" placeholder="End Date" class="date end" name="enddate" value="{{ request.form.enddate }}">
        <input type="test" placeholder="End Time" class="time end" name="endtime" value="{{ request.form.endtime }}">
    </p>

    <br>

    <strong>HDOP Filter</strong><br>
    <select name="hdop_filter">
        <option>HDOP</option>
    </select>


    <select id="hdop_oper" name="hdop_oper">
        <option>&lt;</option>
        <option>&gt;</option>
        <option>&ge;</option>
        <option>&le;</option>
        <option>&#61;</option>
        <option selected disabled value=''></option>
    </select>


        HDOP Value;
        <input type="number" id="hdop" name="hdop" min="0" max="2" step=".1">


<input class="btn-default" type="submit" value="Update Search">
<br>
<strong>*Number of points found: </strong>{{points_len}}
</form>
<br>
<br>





    <h4>{{error}}</h4>
    <br>
    <p><strong>Date =</strong> YYYY-MM-DD  <strong>Time =</strong> HH:MM:SS</p>


    {% for point in points %}
    <pre>
    <strong>Date:</strong> {{ point.DATE }} <strong>Time:</strong> {{ point.TSTAMP }}
    <strong>Latitude:</strong>  {{ point.LAT }}  <strong>Longitude:</strong> {{ point.LON }}
    <strong>Source File:</strong> {{point.FILE }}</pre>
    {% endfor %}





            <!-- datetime formatting https://codex.wordpress.org/Formatting_Date_and_Time -->
            <!-- http://jonthornton.github.io/jquery-timepicker/ -->
            <script>
                $('#basicExample .time').timepicker({
                    'scrollDefault': 'now',
                    'showDuration': true,
                    'timeFormat': 'H:i:s'
                });

                $('#basicExample .date').datepicker({
                    'scrollDefault': 'now',
                    'format': 'yyyy-mm-dd',
                    'autoclose': true
                });
                $(document).ready(ready);

                var basicExampleEl = document.getElementById('basicExample');
                var datepair = new Datepair(basicExampleEl);
            </script>
            <!-- END Script for date time picker -->


HDOP过滤器
HDOP &通用电气; &乐; = HDOP值;
*找到的点数:{{points\u len}

{{error}}
日期=YYYY-MM-DD时间=HH:MM:SS

{点中的点的百分比%}
if request.form.get('hdop_oper') and request.form.get('hdop'):
日期:{{point.Date}}时间:{{point.TSTAMP} 纬度:{{point.LAT}}经度:{{point.LON} 源文件:{{point.File} {%endfor%} $('#basicExample.time')。时间选择器({ '滚动默认值':'现在', “showDuration”:正确, “时间格式”:“H:i:s” }); $('#basicExample.date').datepicker({ '滚动默认值':'现在', “格式”:“yyyy-mm-dd”, “自动关闭”:正确 }); $(文件)。就绪(就绪); var basicexamplele=document.getElementById('basicExample'); var datepair=新的日期对(基本示例);
每当我选择所有日期时间值,而没有hdop值时,flask就会返回一个“错误请求”。但是,如果我只选择hdop过滤器信息,而不选择日期时间,它将按预期返回数据。有什么线索吗?除了它们的形式类型之外,我看不出这两种类型有什么不同


谢谢你看这个

错误出现在获取hdop_oper和hdop的表单值的方法调用中

在烧瓶中获得可选形式的正确方法是使用以下方法:

if request.form['hdop_oper'] and request.form['hdop']:
而不是:

我想指出的是,Flask的回溯功能不会引发“keyerror”异常,让您猜测真正的问题是什么


我知道这不是为了调试你的代码,但我相信一些Flask pro会发现这个Flask异常。如果没有其他问题,将来可能会有人发现这很有帮助。

在大视图方法中的某个地方有一个未处理的异常。你试过打开调试吗
app.run(debug=True)
Yes,它当前处于启用状态。但是,它没有显示异常,只是传递了一个错误的请求页面。您是否检查了web服务器错误日志?数据包嗅探器的输出?它在终端上说了什么?您是否尝试过使用
pdb
?所以不是为了调试你的代码,我从来没有听说过pdb,我会调查一下。谢谢你的推荐。正如您所看到的,我已经到处添加了print语句,在控制台中,表示“print'hdop and hdop_oper exist'”的行从未执行。这让我相信这是我逻辑上的一个错误,但我已经读了几十遍了,没有任何理由认为它不应该执行。