Forums

Flask's request.data doesn't work

Hey, I try to login by using this function:

    @general_app.route('/signin', methods=['POST'])
    def login():
    status_code = 400
    response = "login details invalid"
    form = json.loads(request.data.decode('utf-8'))# gets password and email inserted by user
    user = User.query.filter_by(email=form['email']).first()
    if user is not None: #checks if email exists in database
        if utils.verify_password(form['password'],user.password) and user.confirmed is True: #if password match and user is authenticated
            user.active = True #I still don't know if this attribute is useful
            db.session.commit()
            status_code = 200
            response = {'access_token' : guard.encode_jwt_token(user)} #encode token

    return json.jsonify(response), status_code

After few tries, I managed to locate the problem, everytime I try to use request.data it throws an exception, no idea why, because when I run it locally it works flawlessly. I couldn't figure what's causing it, any ideas?. by the way, reauestobject is fine, I tried code like if request.method == 'POST' and it works, so I'm clueless. Thank you.

Look at the exception you're getting when you try to access request.data (it will be in you error log) and use that to start debugging what the problem is. Make sure you understand the differences between your local installation and your PythonAnywhere we app (Python version, library versions etc.)