'str' object has no attribute 'decode'. Python 3 error?
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]
As for your fetch()
call, you are explicitly asking for just the first message. Use a range if you want to retrieve more messages. See the documentation:
The message_set options to commands below is a string specifying one or more messages to be acted upon. It may be a simple message number (
'1'
), a range of message numbers ('2:4'
), or a group of non-contiguous ranges separated by commas ('1:3,6:9'
). A range can contain an asterisk to indicate an infinite upper bound ('3:*'
).
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.