Программа, берущая вложения с Яндекс Почты стала выдавать ошибку. Не могу понять причину, прошу помочь :( Примерно полгода нормально работала.
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']
Вот этот метод:
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