title: Get json from request flask
body: <p>Client code:</p>
  
  <pre><code>import requests
  import json
  
  url = 'http://127.0.0.1:5050/login'
  user = "newUser"
  password = "password"
  headers = {'content-type': 'application/json'}
  response = requests.post(url, data={"user": user,"pass": password}, headers = headers)
  </code></pre>
  
  <p>Server code:</p>
  
  <pre><code>from flask import Flask, request, make_response
  
  app = Flask(__name__)
  
  
  @app.route('/login', methods=['GET','POST'])
  def login():    
   if request.method == 'POST':
  
      username = request.form.get("user")
      password = request.form.get("pass")
      //more code
      return make_response("",200)
  
  if __name__ == "__main__":
       app.run(host = "127.0.0.1", port = 5050)
  </code></pre>
  
  <p>The problem is that my username and password are always None.</p>
  
  <p>I also tried using:</p>
  
  <pre><code>content = request.get_json(force = True) 
  password = content['pass']
  </code></pre>
  
  <p>and </p>
  
  <pre><code>request.form['user']
  </code></pre>
  
  <p>When I print the content I have: &lt; Request '<a href="http://127.0.0.1:5050/login" rel="noreferrer">http://127.0.0.1:5050/login</a>' [POST]> .So I cannot find the json send from the client.</p>
  
  <p>EDIT:</p>
  
  <p>I did add json.dumps and used request.get_json() and it worked</p>