-
-
Notifications
You must be signed in to change notification settings - Fork 719
Closed
Labels
staleIssues without activity for more than 60 daysIssues without activity for more than 60 days
Description
Summary.
Expected Result
according to source code, payload can be Dict or bytes:
https://github.com/jpadilla/pyjwt/blob/master/jwt/api_jwt.py#L41
def encode(self,
payload, # type: Union[Dict, bytes]
key, # type: str
algorithm='HS256', # type: str
headers=None, # type: Optional[Dict]
json_encoder=None # type: Optional[Callable]
):
Actual Result
but when I use bytes type:
In [4]: encoded_jwt = jwt.encode(b'payload', 'secret', algorithm='HS256')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-68e83f5ffe2a> in <module>
----> 1 encoded_jwt = jwt.encode(b'payload', 'secret', algorithm='HS256')
~/.venv/freshshop-env/lib/python3.6/site-packages/jwt/api_jwt.py in encode(self, payload, key, algorithm, headers, json_encoder)
47 # Check that we get a mapping
48 if not isinstance(payload, Mapping):
---> 49 raise TypeError('Expecting a mapping object, as JWT only supports '
50 'JSON objects as payloads.')
51
TypeError: Expecting a mapping object, as JWT only supports JSON objects as payloads.
Reproduction Steps
import jwt
encoded_jwt = jwt.encode(b'payload', 'secret', algorithm='HS256')System Information
$ python -m jwt.help
{
"cryptography": {
"version": ""
},
"implementation": {
"name": "CPython",
"version": "3.6.5"
},
"platform": {
"release": "4.15.0-29deepin-generic",
"system": "Linux"
},
"pyjwt": {
"version": "1.7.1"
}
}
Metadata
Metadata
Assignees
Labels
staleIssues without activity for more than 60 daysIssues without activity for more than 60 days