Python httplib and broken tcp connection

How can I tell if a connection has been corrupted using the httplib library? It seems to be something so basic, but I can't seem to find an answer here or Google.

+2


a source to share


1 answer


When connected, you get one of the following values:

http://docs.python.org/library/httplib.html#httplib.HTTPException

you can do something like this.



>>> import httplib
>>> conn = httplib.HTTPConnection("www.python.org")
>>> try:
>>>     conn.request("GET", "/index.html")
>>> except Exception as e:
>>>     #take action according to the error.
>>>     print(type(e))
>>> r1 = conn.getresponse()
>>> print r1.status, r1.reason

      

Example taken from www.python.org and edited

+4


a source







All Articles