Skip to content

Commit c7be83c

Browse files
committed
Return string instead of byte
1 parent 76bd54f commit c7be83c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Usage
4444
4545
>>> import jwt
4646
>>> encoded = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
47-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
48-
47+
>>> print(encoded)
48+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U
4949
>>> jwt.decode(encoded, 'secret', algorithms=['HS256'])
5050
{'some': 'payload'}
5151

docs/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ Example Usage
3030
-------------
3131

3232
.. code-block:: python
33+
.. doctest::
3334

3435
>>> import jwt
3536

3637
>>> encoded_jwt = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
37-
>>> encoded_jwt
38-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'
38+
>>> print(encoded_jwt)
39+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U
3940

4041
>>> jwt.decode(encoded_jwt, 'secret', algorithms=['HS256'])
4142
{'some': 'payload'}

src/jwt/api_jws.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def encode(
110110

111111
# Segments
112112
signing_input = b".".join(segments)
113+
113114
try:
114115
alg_obj = self._algorithms[algorithm]
115116
key = alg_obj.prepare_key(key)
@@ -126,7 +127,9 @@ def encode(
126127

127128
segments.append(base64url_encode(signature))
128129

129-
return b".".join(segments)
130+
encoded_string = b".".join(segments)
131+
132+
return encoded_string.decode("utf-8")
130133

131134
def decode(
132135
self,

0 commit comments

Comments
 (0)