1. 程式人生 > >JWT之byte轉換為str

JWT之byte轉換為str

jwt_token = jwt.encode(payload, APPROVED_PRIVATE_KEY, algorithm='RS256')

生成的是byte型別

byte與str相互轉換:

# bytes object  
 b = b"example"  
  
 # str object  
 s = "example"  
  
 # str to bytes  
 bytes(s, encoding = "utf8")  
  
 # bytes to str  
 str(b, encoding = "utf-8")  
  
 # an alternative method  
 # str to bytes  
 str.encode(s)  
  
 # bytes to str  
 bytes.decode(b)