T
T
Ternick2020-11-11 02:55:45
Python
Ternick, 2020-11-11 02:55:45

Problems when trying to receive emails from pop.yandex.by?

THE CODE
def main(email, password):
  pop = POP3_SSL("pop.yandex.by")
  pop.user(email)
  pop.pass_(password)
  response, lst, octets = pop.list()
  print(response, lst, octets)
  for msgnum, msgsize in [i.split() for i in lst]:
    (resp, lines, octets) = pop.retr(msgnum)# Ошибка возникает тут
    msgtext = "n".join(lines) + "nn"
    message = email.message_from_string(msgtext)
    print(message)
    pop.dele(msgnum)
  pop.quit()

Mistake

b'+OK 1 19430' [b'1 19430'] 9
Traceback (most recent call last):
  File "C:\Users\FFF\Desktop\kkk\main.py", line 89, in <module>
    main(*data)
  File "C:\Users\FFF\Desktop\kkk\main.py", line 79, in main
    (resp, lines, octets) = pop.retr(msgnum)
  File "C:\Users\FFF\AppData\Local\Programs\Python\Python36\lib\poplib.py", line 248, in retr
    return self._longcmd('RETR %s' % which)
  File "C:\Users\FFF\AppData\Local\Programs\Python\Python36\lib\poplib.py", line 183, in _longcmd
    return self._getlongresp()
  File "C:\Users\FFF\AppData\Local\Programs\Python\Python36\lib\poplib.py", line 159, in _getlongresp
    resp = self._getresp()
  File "C:\Users\FFF\AppData\Local\Programs\Python\Python36\lib\poplib.py", line 152, in _getresp
    raise error_proto(resp)
poplib.error_proto: b'-ERR message does not exist or deleted. sc=XnamNVYWfOs1_102349_1-4aab5eef9bfd'


I have no idea why this is happening, I have already tried everything, the web version works fine. The only interesting thing I found was this:
I hope it's not :)
imagea58b4894a9a8c8c2.png

Do you have any idea what is causing this and if it can be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Ternick, 2020-11-11
@Ternick

The trick is that msgnum is represented in byte, but it should be in int, that's the whole point.

FIX

def main(email, password):
  pop = POP3_SSL("pop.yandex.by")
  pop.user(email)
  pop.pass_(password)
  response, lst, octets = pop.list()
  print(response, lst, octets)
  for msgnum, msgsize in [i.split() for i in lst]:
    (resp, lines, octets) = pop.retr(int(msgnum))
    msgtext = "n".join(lines) + "nn"#Нужно отлаживать, тут бред происходит
    message = email.message_from_string(msgtext)# тут тоже
    print(message)
    pop.dele(int(msgnum))
  pop.quit()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question