pwsm / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

Connection Timeout raises wrong exception: 'NoneType' object has no attribute 'makefile' #102

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Try to do an Http request to a server that's not answering:

    foo_server = Http()
    req = ('http://no-answer.example.com/foo.txt?oink=' + oink +
           '&whinny=' + join(whinnies, ',') +
           '&object=' + str(objid))
    resp, content = foo_server.request(req, "POST",
                       headers={"Accept": "text/plain"})

2. Wait until it times out.

What is the expected output? What do you see instead?

I expect to get an exception indicating that the connection timed out.   I 
don't know what exception, but something.   Instead, I get this:

'NoneType' object has no attribute 'makefile'

What version of the product are you using? On what operating system?

I happen to be using 0.6.0, but this problem appears to still be present in the 
head of the tree.

Please provide any additional information below.

This is similar to issue 101, where an ECONNREFUSED results in the same error.  
 You've fixed this by special-casing ECONNREFUSED.   You could do something 
similar for this problem with the following change (relative to 0.6.0):

kali% diff -u python2/httplib2/__init__.py{.orig,}
--- python2/httplib2/__init__.py.orig   2010-06-19 20:42:30.000000000 -0700
+++ python2/httplib2/__init__.py    2010-06-19 20:42:52.000000000 -0700
@@ -52,6 +52,7 @@
 import hmac
 from gettext import gettext as _
 import socket
+import errno

 try:
     import socks
@@ -863,7 +864,10 @@
             except socket.gaierror:
                 conn.close()
                 raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
-            except (socket.error, httplib.HTTPException):
+            except socket.error, e:
+       if e.errno == errno.ECONNTIMEDOUT:
+           raise
+       except httplib.HTTPException:
                 # Just because the server closed the connection doesn't apparently mean
                 # that the server didn't send a response.
                 pass

However, I think this is the wrong solution.   Presumably you're catching this 
exception for some reason--there is some error that's okay to get.   The right 
thing to do is test for the error that's okay to get, and raise if that's not 
the error you got.   That way you don't wind up throwing this completely 
surprising exception for any error you happen not to have made an exception for.

Original issue reported on code.google.com by mel...@gmail.com on 20 Jun 2010 at 4:01

GoogleCodeExporter commented 8 years ago
Er, that should have been ETIMEDOUT, not ECONNTIMEDOUT.   :'}

Original comment by mel...@gmail.com on 20 Jun 2010 at 4:02

GoogleCodeExporter commented 8 years ago

Original comment by joe.gregorio@gmail.com on 11 Feb 2011 at 6:07