Answer the question
In order to leave comments, you need to log in
How can I fix the error with imap?
I have code:
import imaplib, email, os
def code_from_email(user, password):
imap_url = "imap.mail.yahoo.com"
connection = imaplib.IMAP4_SSL(imap_url)
connection.login(user, password)
connection.select("INBOX")
start_message_uid = 1100
result, data = connection.uid('search', None, "FROM", '[email protected]')
code = ''
while code == '':
if result == 'OK':
for num in data[-1].split():
result, data = connection.uid('fetch', num, '(RFC822)')
if result == 'OK':
email_message = email.message_from_bytes(data[0][1])
code = str(email_message.get_payload()[1])
connection.close()
connection.logout()
return code
f = open('emails.txt', 'r')
for line in f.readlines():
user = line.split(':')[0]
password = line.split(':')[1]
print(user, password)
code = code_from_email(user, password)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\imaplib.py", line 610, in login
typ, dat = self._simple_command('LOGIN', user, self._quote(password))
File "C:\Users\User\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\User\AppData\Local\Programs\Python\Python39\lib\imaplib.py", line 1055, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: LOGIN command error: BAD [b'[CLIENTBUG] LOGIN Command arguments invalid']
code = code_from_email('[email protected]', '12345678')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question