问题描述
因此,我正在研究Python脚本以从电子邮件中提取文本,并按照这些说明进行操作这样做.到目前为止,这是脚本:
So I'm working on a Python script to extract text from an email and following these instructions to do so. This is the script thus far:
import imapclient
import pprint
import pyzmail
mymail = "[email protected]"
password = input("Password: ")
imapObj = imapclient.IMAPClient('imap.gmail.com' , ssl=True)
imapObj.login(mymail , password)
imapObj.select_folder('INBOX', readonly=False)
UIDs = imapObj.search(['SUBJECT Testing'])
rawMessages = imapObj.fetch([5484], ['BODY[]'])
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
但是我遇到此错误:
message = pyzmail.PyzMessage.factory(rawMessages[5484]['BODY[]'])
KeyError: 5484
5484是搜索功能找到的电子邮件的ID.我也尝试过放置UID而不是5484,但这也不起作用.预先感谢!
5484 being the ID for the email that the search function finds. I've also tried putting UIDs in instead of 5484, but that doesn't work either. Thanks in advance!
推荐答案
感谢@Madalin Stroe.
Thank you @Madalin Stroe .
我在Win10上使用python3.6.2和pyzmail1.0.3.当我跑步时message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
ERR显示如下:
I use python3.6.2 and pyzmail1.0.3 on Win10.When I run message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
The ERR shows like this:
Traceback (most recent call last):
File "PATH/TO/mySinaEmail.py", line 42, in <module>
message = pyzmail.PyzMessage.factory(rawMessages[4]['BODY[]'])
KeyError: 'BODY[]'
当我将其修改为message = pyzmail.PyzMessage.factory(rawMessages[4][b'BODY[]'])
时,它运行良好.
When I modified this to message = pyzmail.PyzMessage.factory(rawMessages[4][b'BODY[]'])
, it run well.
这篇关于Python电子邮件漫游器Pyzmail/IMAPclient错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!