title: Flask JSON not working: BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand
body: <p>I'm trying to pass user input into flask python file using JSON..
  this is the citizins input element in the html body:</p>
  <pre><code>&lt;form class=&quot;networkform&quot; method=&quot;POST&quot;&gt;
  &lt;input name=&quot;citizens&quot; maxlength=&quot;15&quot; class=&quot;InputStyle&quot; required&gt;
  &lt;button type=&quot;submit&quot; style=&quot;height: 40px; width: 180px; background-color: grey; color:white&quot;&gt;send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>this is the jQuery function in the html file:</p>
  <pre><code>$(&quot;.networkform&quot;).on('submit', function(e){
                  alert(&quot;submit is working&quot;)
  
                  $.ajax({
                      data :
                      {
                         'citizens' : $(&quot;citizens&quot;).val(),
                      },
                      type : 'POST',
                      url : '/Dash'
                  })
                  .done(function(data){
                          $(&quot;.outerDiv&quot;).hide()
  
  
                  })
  
                  e.preventDefault();
          });
  </code></pre>
  <p>and this is the function in the .py file:</p>
  <pre><code>@app.route('/Dash', methods=['POST'])
  def Dash():
  if request.method == 'POST':
      print(&quot;inside post&quot;)
      num_citizins = request.form['citizens']
      print(num_citizins)
      return jsonify({&quot;msg&quot; : &quot;Thanks&quot;})
  </code></pre>
  <p>and here is the main in .py file:</p>
  <pre><code>if __name__ == &quot;__main__&quot;:
    print 'Start'
    main()
    app.run(debug=True)
    print 'Done!'
  </code></pre>
  <p>But for some reason it's not working at all.. here is the error I get:</p>
  <pre><code>BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
  </code></pre>
  <p>KeyError: 'citizens'</p>
  <p>solutions I already tried:</p>
  <ul>
  <li>used app.run(debug=True, threaded=True) instead of app.run(debug=True) in main</li>
  <li>used request.form.get instead of request.form</li>
  <li>removed method=&quot;post&quot; from 
  but nothing works.. each time it gives a different type of errors.. what do you think the problem could be? (if any of those matter; I'm using python 2.7, IDE: pyCharm, Browser: Chrome)</li>
  </ul>