poplib - retr() getting stuck

R

Roopesh

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
 
G

Gabriel Genellina

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.
 
R

Roopesh

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top