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

jwt.decode(None) causeAttributeError: 'NoneType' object has no attribute 'rsplit' #183

Closed
guyskk opened this issue Oct 22, 2015 · 1 comment
Labels

Comments

@guyskk
Copy link

guyskk commented Oct 22, 2015

>>> import jwt
>>> jwt.decode(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\jwt\api_jwt.py", line 61, in decode
    payload, signing_input, header, signature = self._load(jwt)
  File "C:\Python27\lib\site-packages\jwt\api_jws.py", line 135, in _load
    signing_input, crypto_segment = jwt.rsplit(b'.', 1)
AttributeError: 'NoneType' object has no attribute 'rsplit'
>>> 

It should raise jwt.InvalidTokenError.

@maoaiz
Copy link
Contributor

maoaiz commented Oct 22, 2015

I have the same issue.

I think the solution is here: https://github.com/jpadilla/pyjwt/blob/master/jwt/api_jws.py#L135

Change the lines 135 and 136 to:

if not isinstance(jwt, text_type):
    raise DecodeError('Invalid token')

jwt = jwt.encode('utf-8')

I'm working on my fork to make the tests pass with this modifications, later I'll send a pull request 👍

maoaiz added a commit to maoaiz/pyjwt that referenced this issue Oct 22, 2015
… 'rsplit'

The issue also occurs when payload is int raising:
    AttributeError: 'int' object has no attribute 'rsplit'
Test for None and int payload added
@mark-adams mark-adams added the bug label Oct 22, 2015
mark-adams added a commit that referenced this issue Oct 23, 2015
Fixed #183 AttributeError: 'NoneType' object has no attribute 'rsplit'
This was referenced Sep 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants