Client 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)
Server 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)
The problem is that my username and password are always None.
I also tried using:
content = request.get_json(force = True)
password = content['pass']
and
request.form['user']
When I print the content I have: < Request 'http://127.0.0.1:5050/login' [POST]> .So I cannot find the json send from the client.
EDIT:
I did add json.dumps and used request.get_json() and it worked