How to catch socket timeout?

Achim Domma domma at procoders.net
Sun Sep 21 05:07:00 EDT 2003


Hi,

I'm using Python 2.3s timeout sockets and have code like this to read a page
from web:

request = ...
self.page = urllib2.urlopen(request)

and later:

try:
    self.data = self.page.read()
except socket.error,e: ...
except socket.timeout: ...
except timeout: ...

but none of these excepts catches the the timeout while reading the data. I
still get the following exception, which I cannot handle:

...
  File "F:\CrawlingFramework\Rules\Tools\__init__.py", line 91, in __init__
    self.data = self.page.read()
  File "C:\Python23\lib\socket.py", line 283, in read
    data = self._sock.recv(recv_size)
timeout: timed out

Any hint on how to handle this exception or what's going wrong?

regards,
Achim






More information about the Python-list mailing list