["python","python-3.x"]
'str' object has no attribute 'decode'. Python 3 error?

Here is my code: import imaplib from email.parser import HeaderParser conn = imaplib.IMAP4_SSL('imap.gmail.com') conn.login('example@gmail.com', 'password') conn.select() conn.search(None, 'ALL') data = conn.fetch('1', '(BODY[HEADER])') header_data = data[1][0][1].decode('utf-8') At this point I get the error message: AttributeError: 'str' object has no attribute 'decode' Python 3 doesn't have str.decode() anymore, so how can I fix this?
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]