title: Python Flask POST 400 Bad Request Error
body: <p>I'm trying to POST data to a website using flask, when I try to return the data I get a 400 Bad Request error.</p>
  
  <p>Here is my python code that sends the POST request:</p>
  
  <pre><code>import requests
  from random import randint
  
  def Temp():
  return randint(0,20)
  
  
  data = {'windspeed':WindSpeed(), 'Temp': Temp(), 'WindDir':WindDir()}
  r = requests.post('http://10.0.0.119', data = data)
  print (r.text)
  </code></pre>
  
  <p>And this is the server code:</p>
  
  <pre><code>from flask import Flask, request, render_template
  
  
  app = Flask(__name__)
  
  @app.route("/", methods=['GET','POST'])
  def result():
      data = request.get_json(force=True)
      Temp = data['Temp']
      return render_template('main.html', name=Temp)
  
  if __name__ == "__main__":
  app.run()
  </code></pre>
  
  <p>This returns a 400 error when run in a a browser, but the client script gets the correct respone:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Temperature&lt;/h1&gt;
  &lt;p&gt;15&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Where 15 is the data['Temp'] variable.</p>