question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

flask_jwt_extended.exceptions.NoAuthorizationError: Missing Authorization Header

See original GitHub issue
from flask import Flask
from flask_jwt_extended import JWTManager, jwt_required
from flask_restful import Api, Resource

app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True

api = Api(app)
jwt = JWTManager(app)


class SomeRoute(Resource):
    @jwt_required
    def post(self):
        return {'message':'success'}, 200


api.add_resource(SomeRoute, '/some_route', endpoint='some_route')

if __name__ == '__main__':
    app.run(debug=False)

post the url without token or token expired use flask_restful no problem!

but use flask_restplus it will raise exception

from flask import Flask
from flask_jwt_extended import JWTManager, jwt_required
from flask_restplus import Api, Resource

app = Flask(__name__)
app.config['PROPAGATE_EXCEPTIONS'] = True

api = Api(app)
jwt = JWTManager(app)


class SomeRoute(Resource):
    @jwt_required
    def post(self):
        return {'message':'success'}, 200


api.add_resource(SomeRoute, '/some_route', endpoint='some_route')

if __name__ == '__main__':
    app.run(debug=False)

it will return

.......
    raise NoAuthorizationError(errors[0])
flask_jwt_extended.exceptions.NoAuthorizationError: Missing Authorization Header

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
vimalloccommented, Jun 19, 2019

Flask-Restplus has a bug where native flask error handlers don’t work. Hopefully they will fix that eventually, but you should be able to use this as a work around in the mean time: https://github.com/vimalloc/flask-jwt-extended/issues/86#issuecomment-335509456

0reactions
aniketsnv-1997commented, Sep 1, 2020

Also, when I visit the api http://127.0.0.1:5000/add-a-new-user while using flask_restplus, I get the error as TypeError: ShowUsersForm() takes no arguments. However, I am not passing any parameter to the api. The same route works fine while using flask_restful

The resource code is ` class ShowUsersForm(Resource): def get(self): # current_user = UsersModel.find_by_email_address(get_jwt_identity()).name

    headers = {'Content-Type': 'text/html'}
    return make_response(render_template("./users/forms/add_user.html",
                                         title="Add User",
                                         current_user="current_user",
                                         roles=RolesModel.get_all_roles(),
                                         projects=ProjectsModel.get_all_projects(),
                                         rights=RightsModel.get_all_rights()
                                         )
                         , 200, headers)

`

As a result, I am deadlocked between flask_restful and flask_restplus. ANy help upon this will be much appreciated!

`

Read more comments on GitHub >

github_iconTop Results From Across the Web

flask_jwt_extended exceptions NoAuthorizationError
I find the solution for this above issue. While making the request we have to send the headers in the below format.
Read more >
Basic Usage — flask-jwt-extended 4.4.4 documentation
By default, this is done with an authorization header that looks like: Authorization: Bearer <access_token>. We can see this in action using HTTPie....
Read more >
flask_jwt_extended.exceptions.NoAuthorizationError Example
def _decode_jwt_from_headers(): # Verify we have the auth header ... None) if not auth_header: raise NoAuthorizationError("Missing Authorization Header") ...
Read more >
flask-jwt-extended: Fake Authorization Header during testing ...
Answer a question This is the function I wish to test @jwt_required def get_all_projects(self): # implementation not included here I call ...
Read more >
Python get jwt - ProgramCreek.com
"bearer": return None if len(auth) == 1: msg = _("Invalid Authorization header. No credentials provided.") raise exceptions.AuthenticationFailed(msg) elif ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found