1# You are trying to decode an object that is already decoded
2# You have a str, there is no need to decode from UTF-8 anymore
3
4# Simply drop the part
5 .decode('utf-8')
1import imaplib
2from email.parser import HeaderParser
3
4conn = imaplib.IMAP4_SSL('imap.gmail.com')
5conn.login('example@gmail.com', 'password')
6conn.select()
7conn.search(None, 'ALL')
8data = conn.fetch('1', '(BODY[HEADER])')
9header_data = data[1][0][1].decode('utf-8')
10