'str' object has no attribute 'decode'. Python 3 error?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Track title: CC E Schuberts Piano Sonata D 784 in A
--
Chapters
00:00 Question
00:46 Accepted answer (Score 286)
01:09 Answer 2 (Score 69)
01:32 Answer 3 (Score 54)
01:56 Answer 4 (Score 50)
02:08 Thank you
--
Full question
https://stackoverflow.com/questions/2858...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #python3x #imaplib
#avk47
--
Track title: CC E Schuberts Piano Sonata D 784 in A
--
Chapters
00:00 Question
00:46 Accepted answer (Score 286)
01:09 Answer 2 (Score 69)
01:32 Answer 3 (Score 54)
01:56 Answer 4 (Score 50)
02:08 Thank you
--
Full question
https://stackoverflow.com/questions/2858...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #python3x #imaplib
#avk47
ACCEPTED ANSWER
Score 301
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 .decode('utf-8') part:
header_data = data[1][0][1]
ANSWER 2
Score 75
If you land here using jwt authentication after the PyJWT v2.0.0 release (22/12/2020), you might want to freeze your version of PyJWT to the previous release in your requirements.txt file.
PyJWT==1.7.1
ANSWER 3
Score 57
Begining with Python 3, all strings are unicode objects.
a = 'Happy New Year' # Python 3
b = unicode('Happy New Year') # Python 2
The instructions above are the same. So I think you should remove the .decode('utf-8') part because you already have a unicode object.
ANSWER 4
Score 56
Use it by this Method:
str.encode().decode()