0

I have two python script to do listener on gmail to get incoming emails but when I run it I am gotten a following error any help will be welcome. also if anu other script will be welcom Already thanks. the first script:

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)

the output error:

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

the second script: got it from this link

the error:

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
timomo
  • 67
  • 1
  • 8
  • 1
    I tested first script and it works without problems on Linux Mint 20, Python 3.8. Maybe it is problem only on Windows, or only in Python 3.9 – furas Dec 22 '20 at 21:38
  • 1
    I tested with `Python 3.9` and it gives error. Maybe they changed something in `imaplib` and `email_listener` has problem. As I know `Python 3.9` is very fresh version so better use little older `3.8`. You can also send this problem to author of `email_listener` and maybe it will fix it in next version. – furas Dec 22 '20 at 21:41

1 Answers1

1

email_listener works on Python 3.8 but not on Python 3.9

I found that email_listener uses module IMAPClient which has problem with new IMAP_SSL.open() in standard module imaplib.

On page IMAPClient you can see

Python versions 2.7 and 3.4 through 3.7 are officially supported.

so you have to use Python 3.8 and wait until IMAPClient fix it.

furas
  • 134,197
  • 12
  • 106
  • 148
  • i switched to 3.8 its work fine, only one last thing i got this error i think is related to decoding, any help or must creat a naw question – timomo Dec 25 '20 at 15:42