K
K
keltkelt2020-06-11 01:10:04
Python
keltkelt, 2020-06-11 01:10:04

Where is the error in processing mail in python?

The program that takes attachments from Yandex Mail began to give an error. I can’t understand the reason, please help :( It worked fine for about six months.

Traceback (most recent call last):
  File "system.py", line 68, in <module>
    download(config[key][2],key,imap)
  File "system.py", line 36, in download
    result, data = mail.fetch(id, "(RFC822)")
  File "C:\Python38\lib\imaplib.py", line 539, in fetch
    typ, dat = self._simple_command(name, message_set, message_parts)
  File "C:\Python38\lib\imaplib.py", line 1205, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "C:\Python38\lib\imaplib.py", line 1030, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: FETCH command error: BAD [b'Command syntax error. sc=AuCh9V5LFa61_100756_5-87ad899d6f4d']


Here is the method:

def download(address, name, mail):
    result, data = mail.search(None, 'FROM '+address)
    ids = data[0]
    exit=False
    for id in reversed(ids.split()):
        if exit: break
        result, data = mail.fetch(id, "(RFC822)") # НА ЭТО РУГАЕТСЯ
        raw_email = data[0][1] 
        try:
            email_message = email.message_from_string(raw_email)  
        except TypeError:
            email_message = email.message_from_bytes(raw_email)

        for part in email_message.walk():
            if "application" in part.get_content_type() :
                filename = part.get_filename()
                filename=str(email.header.make_header(email.header.decode_header(filename)))
                if not(filename): filename = "test.txt"         
                print ("-- обновлен прайс ",name)       
                fp = open(os.path.join(".\\prices", name), 'wb')
                fp.write(part.get_payload(decode=1))
                fp.close
                exit=True  
                break

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-06-12
@dimonchik2013

look for what has changed - the Python version, most likely

W
Walker2000, 2020-06-13
@Walker2000

I have a similar problem. And it came about at that time. It did not change either in the version of Python or libraries. More like some changes on the side of Yandex-Mail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question