如何解决如何修复python脚本电子邮件侦听器
我有两个 python 脚本可以在 gmail 上做侦听器以获取传入的电子邮件,但是当我运行它时,我收到了以下错误,欢迎任何帮助。 此外,如果 anu 其他脚本将受到欢迎 已经谢谢了。 第一个脚本:
import email_listener
# Set your email,password,what folder you want to listen to,and where to save attachments
email = "example@gmail.com"
app_password = "password"
folder = "Inbox"
attachment_dir = "/path/to/attachments"
el = email_listener.EmailListener(email,app_password,folder,attachment_dir)
# Log into the IMAP server
el.login()
# Get the emails currently unread in the inbox
messages = el.scrape()
print(messages)
# Start listening to the inbox and timeout after an hour
timeout = 60
el.listen(timeout)
输出错误:
C:\Users\PC Sony>"C:/Users/PC Sony/AppData/Local/Programs/Python/Python39/python.exe" "c:/Users/PC Sony/Desktop/elzero/elzero/import email_listener.PY"
Traceback (most recent call last):
File "c:\Users\PC Sony\Desktop\elzero\elzero\import email_listener.PY",line 11,in <module>
con.login()
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\site-packages\email_listener\__init__.py",line 83,in login
self.server = IMAPClient('imap.gmail.com')
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\site-packages\imapclient\imapclient.py",line 254,in __init__
self._imap = self._create_IMAP4()
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\site-packages\imapclient\imapclient.py",line 288,in _create_IMAP4
return tls.IMAP4_TLS(self.host,self.port,self.ssl_context,File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\site-packages\imapclient\tls.py",line 44,in __init__
imaplib.IMAP4.__init__(self,host,port)
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\imaplib.py",line 202,in __init__
self.open(host,port,timeout)
TypeError: open() takes 3 positional arguments but 4 were given
第二个脚本: 从这个link
错误:
Traceback (most recent call last):
File "c:\Users\PC Sony\Desktop\elzero\elzero\import imaplib.py",line 68,in <module>
result,data = server.uid('fetch',uid,'(RFC822)') # fetch entire message
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\imaplib.py",line 890,in uid
typ,dat = self._simple_command(name,command,*args)
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\imaplib.py",line 1230,in _simple_command
return self._command_complete(name,self._command(name,*args))
File "C:\Users\PC Sony\AppData\Local\Programs\Python\Python39\lib\imaplib.py",line 988,in _command
data = data + b' ' + arg
TypeError: can't concat int to bytes
解决方法
email_listener
适用于 Python 3.8
但不适用于 Python 3.9
我发现 email_listener
使用的模块 IMAPClient
与标准模块 IMAP_SSL.open()
中的 new imaplib
有问题。
在第 IMAPClient
页上,您可以看到
官方支持 Python 版本 2.7 和 3.4 到 3.7。
所以你必须使用 Python 3.8
并等到 IMAPClient
修复它。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。