Posted on 16th September 2024|502 views
How to resolve the python error str object has no attribute decode?
I am getting an error called str object has no attribute decode please help me here is my code:
import imaplib
from email.parser import HeaderParser
conn = imaplib.IMAP4_SSL('imap.gmail.com')
conn.login('mindmajix@gmail.com', 'password')
conn.select() conn.search(None, 'ALL')
data = conn.fetch('1', '(BODY[HEADER])')
header_data = data[1][0][1].decode('utf-8')
Posted on 16th September 2024| views
You are trying to decode an object which is already decoded. You already have a str, UTF-8 is not required anymore.
Simply avoid the .decode('utf-8') line:
header_data = data[1][0][1]