Skip to content

Instantly share code, notes, and snippets.

@marcesher marcesher/
Last active Aug 29, 2015

What would you like to do?
Strange hanging behavior with python httplib in one environment only
# Problem: In only one environment, I see behavior with httplib where issuing a request against a FQDN will hang, but works fine with a URL without the domain
# eg request("GET", "") hangs, but request("GET", "/") does not
# I only see this problem in one of our hosting environments, on both 2.6 and 2.7
# I cannot replicate it anywhere else
import httplib
cn = httplib.HTTPConnection("", 80, timeout=5)
cn.request("GET", "/")
res = cn.getresponse()
print("\n\nResponse length: %s\n\n" % len( )
# This hangs in our hosting environment, but I can't replicate it anywhere else
cn.request("GET", "")
res = cn.getresponse()
print("\n\nResponse length: %s\n\n" % len( )
$ python2.7
send: 'GET / HTTP/1.1\r\nHost:\r\nAccept-Encoding: identity\r\n\r\n'
reply: 'HTTP/1.1 301 Moved Permanently\r\n'
header: Location:
header: Content-Type: text/html; charset=UTF-8
header: Date: Wed, 19 Aug 2015 12:35:52 GMT
header: Expires: Fri, 18 Sep 2015 12:35:52 GMT
header: Cache-Control: public, max-age=2592000
header: Server: gws
header: Content-Length: 219
header: X-XSS-Protection: 1; mode=block
header: X-Frame-Options: SAMEORIGIN
Response length: 219
send: 'GET HTTP/1.1\r\nHost:\r\nAccept-Encoding: identity\r\n\r\n'
Traceback (most recent call last):
File "", line 11, in <module>
res = cn.getresponse()
File "/usr/lib64/python2.7/", line 1013, in getresponse
File "/usr/lib64/python2.7/", line 402, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python2.7/", line 360, in _read_status
line = self.fp.readline()
File "/usr/lib64/python2.7/", line 430, in readline
data = recv(1)
socket.timeout: timed out

This comment has been minimized.

Copy link

willbarton commented Aug 19, 2015

I'd be curious to see you try this in a file:

Accept-Encoding: identity

And then:

nc 80 < my_http_get_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.