본문 바로가기

스파르타코딩 내일배움캠프

AttributeError: 'str' object has no attribute 'decode' 에러

파이썬에서 AttributeError: 'str' object has no attribute 'decode' 이런 메시지가 뜨시면 

 

해당 코드 줄의 .decode() 부분을 지우시면 됩니다. 

 

이미 decode가 되었기 때문에 decode할게 없다는 뜻 입니다. 

 

국내 블로그에는 저 내용이 별로 없어서 올립니다. 

 

출처는 아래 링크입니다. 

 

AttributeError: 'str' object has no attribute 'decode' jwt decode Code Example (codegrepper.com)

 

AttributeError: 'str' object has no attribute 'decode' jwt decode Code Example

# You are trying to decode an object that is already decoded # You have a str, there is no need to decode from UTF-8 anymore # Simply drop the part .decode('utf-8')

www.codegrepper.com

 

원래는 '스파르타코딩-웹 심화'반에서 나오는 에러를 같이 수업 듣는 사람들과 공유 했는데, 팀장님께서 블로그에 업로드 하는게 어떻겠냐고 하셨고, 저도 생각해보니 국내 블로그에는 이 내용이 별로 없어서 올립니다. 

 

아래는 제가 "스파르타코딩 - 내일배움캠프"의 slack에 올린 원문입니다. 

 

웹심화 4주차 강의와 관련해서 글을 올립니다.'4-3 회원가입' 수업을 들으실 때 회원가입 후 로그인을 하려고 하면token = jwt.encode(payload, SECRET_KEY, algorithm='HS256').decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'이런 메시지가 뜰 수 있습니다. 파이썬 버전에 따라 다를 수 있을텐데, 이런 메시지가 뜨시는 분들은

token = jwt.encode(payload, SECRET_KEY, algorithm='HS256').decode('utf-8')

app.py 파일의 95분 줄 마지막에 .decode('utf-8')지우시면 됩니다.

token = jwt.encode(payload, SECRET_KEY, algorithm='HS256')

AttributeError: 'str' object has no attribute 'decode' jwt decode Code Example (codegrepper.com)이 웹사이트에 따르면 ('utf-8')이 이미 decode가 되어서 .decode('utf-8')이 필요가 없기 때문에 저 부분을 삭제하면 된다고 합니다.참고하시면 되겠습니다.

 

AttributeError: 'str' object has no attribute 'decode' jwt decode Code Example

# You are trying to decode an object that is already decoded # You have a str, there is no need to decode from UTF-8 anymore # Simply drop the part .decode('utf-8')

www.codegrepper.com