Waiting for receiving data

Anjanesh Lekshminarayanan mail at anjanesh.net
Mon Nov 23 21:30:19 CET 2009

fp = urllib.urlopen(url)
data = fp.read()

Retrieving XML data via an XML service API.
Very often network gets stuck in between. No errors / exceptions.


  File "get-xml.py", line 32, in <module>
    fp = urllib.urlopen(url)
  File "/usr/lib/python2.6/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.6/urllib.py", line 206, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.6/urllib.py", line 348, in open_http
    errcode, errmsg, headers = h.getreply()
  File "/usr/lib/python2.6/httplib.py", line 1048, in getreply
    response = self._conn.getresponse()
  File "/usr/lib/python2.6/httplib.py", line 974, in getresponse
  File "/usr/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/lib/python2.6/socket.py", line 397, in readline
    data = recv(1)

Is there I can do to try something else if its taking too long to
retrieve from the network ? Like kill previous attempt and retry ?

Anjanesh Lekshmnarayanan

More information about the Python-list mailing list