Flask-jwt error with Flask-restful if request contain JSON Flask-jwt error with Flask-restful if request contain JSON flask flask

Flask-jwt error with Flask-restful if request contain JSON


So I ran this in different possible combination and the issue cannot be replicated. I user below server file

from flask import Flaskfrom flask_jwt import JWT, jwt_required, current_identityfrom flask_restful import Api, Resourcefrom werkzeug.security import safe_str_cmpclass User(object):    def __init__(self, id, username, password):        self.id = id        self.username = username        self.password = password    def __str__(self):        return "User(id='%s')" % self.idusers = [    User(1, 'xyz', 'xyz'),    User(2, 'user2', 'abcxyz'),]username_table = {u.username: u for u in users}userid_table = {u.id: u for u in users}def authenticate(username, password):    user = username_table.get(username, None)    if user and safe_str_cmp(user.password.encode('utf-8'), password.encode('utf-8')):        return userdef identity(payload):    user_id = payload['identity']    return userid_table.get(user_id, None)app = Flask(__name__)app.debug = Trueapp.config['SECRET_KEY'] = 'super-secret'jwt = JWT(app, authenticate, identity)api = Api(app)class HelloWorld(Resource):    @jwt_required()    def get(self, user_id):        return {'hello': 'world'}    @jwt_required()    def put(self, user_id):        user = None        if user is None:            return {"message": "User not found!"}, 404api.add_resource(HelloWorld, '/<string:user_id>')if __name__ == '__main__':    app.run()

requirements.txt

aniso8601==1.3.0click==6.7Flask==0.12.2Flask-JWT==0.3.2Flask-RESTful==0.3.6itsdangerous==0.24Jinja2==2.9.6MarkupSafe==1.0PyJWT==1.4.2python-dateutil==2.6.1pytz==2017.2six==1.11.0Werkzeug==0.12.2

And then in POSTMAN all requests working whether JSON is sent or not

Without BodyWithout Body

With BodyWith Body

It may have to do with some package version issue. I would suggest you run

pip install flask-jwt flask-restful --force --upgrade

To get the latest versions and see if that fixes the issue. If not then try running with debug=True in your app.run()