我正在从python提取我的gmail电子邮件,并且所有电子邮件都已正确提取。但是突然之间,我的一些电子邮件开始使用随机字符,这些字符毫无意义。
def extract_body(payload):
if isinstance(payload,str):
return payload
else:
return '\n'.join([extract_body(part.get_payload()) for part in payload])
conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login(username, password)
conn.select()
typ, data = conn.search( None, 'FROM email@example.com')
try:
for num in data[0].split():
typ, msg_data = conn.fetch(num, '(RFC822)')
for response_part in msg_data:
if isinstance(response_part, tuple):
msg = email.message_from_bytes(response_part[1])
payload=msg.get_payload()
body=extract_body(payload)
奇怪的输出:
PEhUTUw + DQogIDxoZWFkPg0KICAgIDxNRVRBIGh0dHAtZXF1aXY9IkNvbnRlbnQtVHlw ZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PXV0Zi0xNiI + DQogICAgPHN0eWxl Pg0KICAgICAgICAgIFREIHsgRk9OVC1TSVpFOiA5cHQ7IEZPTlQtRkFNSUxZOiB2ZXJk YW5hLCB0YWhvbWEsIGFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWY7IH0NCiAgICAg ICAgICBCT0RZIHsgRk9OVC1TSVpFOiA5cHQ7IEZPTlQtRkFNSUxZOiB2ZXJkYW5hLCB0 YWhvbWEsIGFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWY7IH0NCiAgICAgICAgICBT cGFuLlNtYWxsIHsgRk9OVC1TSVpFOiA4cHQ7IEZPTlQtRkFNSUxZOiB2ZXJkYW5hLCB0 YWhvbWEsIGFyaWFsLCBoZWx2ZXRpY2EsIHNhbnMtc2VyaWY7IH0NCiAgICAgICAgICBU
我提取信息的方式有问题吗?