huangbop / python-rest-client

Automatically exported from code.google.com/p/python-rest-client
0 stars 0 forks source link

Usability issue with failing TCP connections #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Assuming nothing listening on 127.0.0.1 port 80 ...
2. Run the following sample code ...

>>> from restful_lib import Connection
>>> c = Connection('http://localhost')
>>> print c.request('/api/foo/', method='GET')

What is the expected output?

Some kind of error message/exception stating 'connection refused' or
'connection failed'.

What do you see instead?

The rather cryptic AttributeError (with traceback) :-

Traceback (most recent call last):
  File "/tmp/test2.py", line 4, in <module>
    print c.request('/api/foo/', method='GET')
  File "/tmp/restful_lib.py", line 127, in request
    resp, content = self.h.request(u"%s://%s%s" % (self.scheme, self.host,
u'/'.join(request_path)), method.upper(), body=body, headers=headers )
  File "/usr/lib/python2.5/site-packages/httplib2/__init__.py", line 1101,
in request
    (response, content) = self._request(conn, authority, uri, request_uri,
method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.5/site-packages/httplib2/__init__.py", line 887,
in _request
    (response, content) = self._conn_request(conn, request_uri, method,
body, headers)
  File "/usr/lib/python2.5/site-packages/httplib2/__init__.py", line 859,
in _conn_request
    response = conn.getresponse()
  File "/usr/lib/python2.5/httplib.py", line 926, in getresponse
    method=self._method)
  File "/usr/lib/python2.5/httplib.py", line 324, in __init__
    self.fp = sock.makefile('rb', 0)
AttributeError: 'NoneType' object has no attribute 'makefile'

What version of the product are you using?

Release 0.2

Any other information?

This does not occur when an HTTP server is up and listening for connections
;-) Not sure if this is a problem with underlying httplib2 library or the
way in which it is being called.

Original issue reported on code.google.com by drk...@gmail.com on 12 Oct 2009 at 10:30

GoogleCodeExporter commented 9 years ago
With nothing running on port 80 I received an output as ugly as yours but mine 
had a Connection refused at the end. (Python 2.6.5)

>>> from restful_lib import Connection
httplib2/__init__.py:29: DeprecationWarning: the md5 module is deprecated; use 
hashlib instead
  import md5
httplib2/__init__.py:44: DeprecationWarning: the sha module is deprecated; use 
the hashlib module instead
  import sha
>>> c = Connection('http://localhost')
>>> print c.request('/api/foo/', method='GET')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "restful_lib.py", line 127, in request
    resp, content = self.h.request(u"%s://%s%s" % (self.scheme, self.host, u'/'.join(request_path)), method.upper(), body=body, headers=headers )
  File "httplib2/__init__.py", line 1050, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "httplib2/__init__.py", line 854, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "httplib2/__init__.py", line 823, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python2.6/httplib.py", line 910, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.6/httplib.py", line 947, in _send_request
    self.endheaders()
  File "/usr/lib/python2.6/httplib.py", line 904, in endheaders
    self._send_output()
  File "/usr/lib/python2.6/httplib.py", line 776, in _send_output
    self.send(msg)
  File "/usr/lib/python2.6/httplib.py", line 735, in send
    self.connect()
  File "httplib2/__init__.py", line 715, in connect
    raise socket.error, msg
socket.error: [Errno 111] Connection refused

Original comment by dr.chamb...@gmail.com on 11 Oct 2010 at 1:55