[PyJWT] jwt.encode( )가 bytes-str이 아닌 str타입을 리턴 시

jwt.decode('utf-8')에서 AttributeError: 'str' object has no attribute 'decode'. AttributeError: 'str' object has no attribute 'decode'. 와 같은 AtrributeError가 발생하였다.

원인

원인은 PyJWT 모듈의 버전 2.0.0 부터 jwt.encode가 리턴한 token의 타입이 bytes에서 str로 변경되였기 때문이다. 

해결 방법

PyJWT의 버전을 2.0.0의 직전 버전인 1.7.1으로 변경하면 임시방편으로 해당 에러는 발생하지 않는다.

추후 2.0.0 버전 이상에서는 decode를 어떻게 하는지 추가할 예정이다.

참고) https://github.com/jazzband/djangorestframework-simplejwt/issues/326

 

AttributeError: 'str' object has no attribute 'decode'. · Issue #326 · jazzband/djangorestframework-simplejwt

Hey– I'm trying to get this package integrated and I'm getting something odd here when a jwt is being created. Is anyone else running into this issue? I'm on 4.4.0 AttributeError: '...

github.com