File tree Expand file tree Collapse file tree 3 files changed +9
-5
lines changed
Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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'}
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments