2

How do I find out if a connection has been broken using the httplib library? Seems like something so basic yet I can't find the answer on here or google.

0

1 Answer 1

4

While Connecting You get one of these:

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

you could 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.