title: python 3 flask how to debug 400 Bad Request: The browser (or proxy) sent a request that this server could not understand
body: <p>New to Python 3.7 RESTFUl API. In the following POST endpoint, I keep getting the following error message in the POST endpoint, but the GET endpoint works fine. </p>
  
  <pre><code>Exception in _query: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
  </code></pre>
  
  <p>Wonder how can I debug this? There is no clear error message in SQL or Python. Thank you.</p>
  
  <pre><code># all the imports
  import os
  import sqlite3
  from flask import Flask, request, session, g, redirect, url_for, abort, \
       render_template, flash
  
  app = Flask(__name__) # create the application instance :)
  app.config.from_object(__name__) # load config from this file , flaskr.py
  
  def init_db():
      db = get_db()
      with app.open_resource('schema.sql', mode='r') as f:
          db.cursor().executescript(f.read())
  
      print('create database successfully')
      db.commit()
  
  # there are other codes in between being ignored
  
  @app.route('/', methods=['GET'])
  def show_entries():
  
      try:
          db = get_db()
          # cur = db.execute('select  * from mouse_tracking')
  
          check_table="SELECT name FROM sqlite_master WHERE name = 'mouse_tracking' and type = 'table'; "
  
          print(check_table)
          cur = db.execute(check_table)
  
          entries = cur.fetchall()
  
          print(type(entries))
  
          print(entries)
  
      except sqlite3.Error as e:
          print("Database error: %s" % e)
      except Exception as e:
          print("Exception in _query: %s" % e)
  
      return render_template('show_entries.html', entries=entries)
  
  
  
  @app.route('/add', methods=['POST'])
  def add_entry():
  
      try:
  
          print('posting the content')
  
          db = get_db()
          db.execute('insert into mouse_tracking (user_id, date, x, y, click) values (?, ?, ?, ?, ?)',
                       [request.form['user_id'], request.form['date'], request.form['x'], request.form['y']
                           , request.form['click']])
          db.commit()
          flash('New entry was successfully posted')
  
      except sqlite3.Error as e:
          print("Database error: %s" % e)
      except Exception as e:
          print("Exception in _query: %s" % e)
      return redirect(url_for('show_entries'))
  </code></pre>
  
  <p>Here is the show_entries.html</p>
  
  <pre><code>{% extends "layout.html" %}
  {% block body %}
    {% if session.logged_in %}
      &lt;form action="{{ url_for('add_entry') }}" method=post class=add-entry&gt;
        &lt;dl&gt;
          &lt;dt&gt;Title:
          &lt;dd&gt;&lt;input type=text size=30 name=title&gt;
          &lt;dt&gt;Text:
          &lt;dd&gt;&lt;textarea name=text rows=5 cols=40&gt;&lt;/textarea&gt;
          &lt;dd&gt;&lt;input type=submit value=Share&gt;
        &lt;/dl&gt;
      &lt;/form&gt;
    {% endif %}
    &lt;ul class=entries&gt;
    {% for entry in entries %}
      &lt;li&gt;&lt;h2&gt;{{ entry.title }}&lt;/h2&gt;{{ entry.text|safe }}
    {% else %}
      &lt;li&gt;&lt;em&gt;Unbelievable.  No entries here so far&lt;/em&gt;
    {% endfor %}
    &lt;/ul&gt;
  {% endblock %}
  </code></pre>
  
  <p>here is the curl call</p>
  
  <pre><code>curl --location --request POST 'http://127.0.0.1:5000/add' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Basic cm9vdDpkZWZhdWx0' \
  --data-raw '{
      "user_id": "1",
      "date": "2020-01-01",
      "x": "720",
      "y": "50",
      "click": "0"
  }'
  </code></pre>
  
  <p>Here is the schema.sql</p>
  
  <pre><code>create table if not exists mouse_tracking (
    user_id integer not null,
    date timestamp not null,
    x integer not null,
    y integer not null,
    click integer not null
  );
  </code></pre>