poplib - retr() getting stuck

Discussion in 'Python' started by Roopesh, Jun 20, 2008.

  1. Roopesh

    Roopesh Guest

    Hi,

    I am using poplib's retr() to fetch mails from my gmail account. It
    works fine, in some cases it gets stuck inside the retr() method and
    does not come out.

    From the logs I could find that when retr() is called, it stops
    executing further statements, nor does it throw an exceptions but
    simply stops. My code is roughly like the foll:

    try:
    print "1"
    mymsg = M.retr(msg_no)
    print "2"
    except poplib.error_proto, e:
    print "exception1"
    except Exception, e:
    print "exception2"

    What can be the reason for this? Can anyone help me.

    Thanks
    Roopesh
     
    Roopesh, Jun 20, 2008
    #1
    1. Advertising

  2. En Fri, 20 Jun 2008 04:37:32 -0300, Roopesh <>
    escribió:

    > I am using poplib's retr() to fetch mails from my gmail account. It
    > works fine, in some cases it gets stuck inside the retr() method and
    > does not come out.


    Probably the server stopped responding. By default, sockets have no
    timeout value set - that is, a recv() call may block forever.
    Try using socket.setdefaulttimeout
    <http://docs.python.org/lib/module-socket.html> before creating the
    connection, or search this group for past responses to this same problem.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Jun 24, 2008
    #2
    1. Advertising

  3. Roopesh

    Roopesh Guest

    Thanks for the help.

    At present I have modified the poplib code as follows (In POP3 and
    POP3_SSL classes): Is it the correct way?

    def __init__(self, host, port = POP3_PORT):
    self.host = host
    self.port = port
    msg = "getaddrinfo returns an empty list"
    self.sock = None

    socket.setdefaulttimeout(30)

    for res in socket.getaddrinfo(self.host, self.port, 0,
    socket.SOCK_STREAM):
    af, socktype, proto, canonname, sa = res
    try:
    self.sock = socket.socket(af, socktype, proto)
    self.sock.connect(sa)
    except socket.error, msg:

    Thanks
    Roopesh
     
    Roopesh, Jun 26, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    0
    Views:
    3,802
  2. Simon Burton

    spam killing with poplib

    Simon Burton, Sep 20, 2003, in forum: Python
    Replies:
    7
    Views:
    379
    Donn Cave
    Sep 21, 2003
  3. Replies:
    2
    Views:
    1,133
    Mike Meyer
    Jun 22, 2005
  4. GM
    Replies:
    1
    Views:
    311
    John Machin
    Sep 9, 2006
  5. EuGeNe Van den Bulke

    poplib.retr doens't flag message as read

    EuGeNe Van den Bulke, Jun 19, 2007, in forum: Python
    Replies:
    3
    Views:
    319
    Gabriel Genellina
    Jun 20, 2007
Loading...

Share This Page