Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"assert exc_value is e" assertion error #108

Closed
rayrapetyan opened this issue Dec 22, 2017 · 2 comments
Closed

"assert exc_value is e" assertion error #108

rayrapetyan opened this issue Dec 22, 2017 · 2 comments

Comments

@rayrapetyan
Copy link

rayrapetyan commented Dec 22, 2017

Hi. I'm getting a following exception:

Traceback (most recent call last):
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask/app.py", line 1617, in full_dispatch_request
    rv = self.dispatch_request()
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask/app.py", line 1603, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_restful/__init__.py", line 480, in wrapper
    resp = resource(*args, **kwargs)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask/views.py", line 84, in view
    return self.dispatch_request(*args, **kwargs)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_restful/__init__.py", line 595, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_jwt_extended/view_decorators.py", line 33, in wrapper
    jwt_data = _decode_jwt_from_request(request_type='access')
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_jwt_extended/view_decorators.py", line 194, in _decode_jwt_from_request
    decoded_token = _decode_jwt_from_headers()
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_jwt_extended/view_decorators.py", line 156, in _decode_jwt_from_headers
    return decode_token(encoded_token)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_jwt_extended/utils.py", line 77, in decode_token
    csrf_value=csrf_value
  File "/ara/venv_python/flask/lib/python2.7/site-packages/flask_jwt_extended/tokens.py", line 106, in decode_jwt
    data = jwt.decode(encoded_token, secret, algorithms=[algorithm])
  File "/ara/venv_python/flask/lib/python2.7/site-packages/jwt/api_jwt.py", line 64, in decode
    options, **kwargs)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/jwt/api_jws.py", line 116, in decode
    key, algorithms)
  File "/ara/venv_python/flask/lib/python2.7/site-packages/jwt/api_jws.py", line 186, in _verify_signature
    raise DecodeError('Signature verification failed')
DecodeError: Signature verification failed

It's being intercepted in flask/app.py later, in handle_user_exception function, and fails on:
assert exc_value is e

I've logged e and exc_value, they are:
"Signature verification failed"
and
"'DecodeError' object has no attribute 'code'"

respectively.

Please help to find a workaround! I've tried:

@app.errorhandler(JWTDecodeError)
def handle_jwt_decode_error(e):
    return {'message': str(e)}, 403

found in issue #86 with no success...

@rayrapetyan rayrapetyan changed the title "assert exc_value is e" Assetion error "assert exc_value is e" assertion error Dec 22, 2017
@vimalloc
Copy link
Owner

iirc flask-restful was a fork of flask-restplus or vice-versa, so I'm guessing whatever bug is screwing things up in the flask-restplus library is also breaking things here. If it is the same bug, there isn't anything I can do about it, as it is a problem with their extension breaking native flask functionality and nothing wrong with this extension (#86 has all the details for that).

If you can provide me with a minimum working example, I could dig into it a little deeper and see if it is in fact the same issue.

@rayrapetyan
Copy link
Author

rayrapetyan commented Dec 22, 2017

Sorry, please disregard this issue. It was an error in my custom errors handler which assumed DecodeError has a 'code' attribute which it hasn't:

class CustomRestfulApi(Api):
    def handle_error(self, e):        
        if (type(e).__name__ == 'ApiError' and e.code == 100):
            return self.make_response({'error': {'code': e.code, 'message': e.message}}, 403)
        if type(e).__name__ in ['DecodeError', 'NoAuthorizationError']:
            return self.make_response({'error': {'code': e.code, 'message': type(e).__name__}}, 403)

However there was no way to rewind stack to this place in any sort of Flask back-traces and logs (exceptions are evil after all), found accidentally when building a minimal working example for you. Thank you anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants