I am using gevent 0.13.6, greenlet 0.3.1.
Without patching, python httplib throws "socket.gaierror: [Errno 11004]
getaddrinfo failed", however when patching with gevent it hangs on the
"request" call
Is there anything I can do to avoid this behavior?
Please find sample code below.
import gevent.monkey
gevent.monkey.patch_socket(True, True)
gevent.monkey.patch_select(True)
gevent.monkey.patch_ssl()
gevent.monkey.patch_httplib()
import httplib
url = 'www.google.com'
conn = httplib.HTTPConnection(url, timeout=2)
headers = {"Content-type": "application/json"}
print 'before conn.request'
conn.request("GET", url,headers=headers)
print 'after conn.request'
response = conn.getresponse()
if response.status == 200:
data = response.read()
print data
else:
raise Exception("HTTP %d %s"%(response.status,response.msg))
conn.close()
# Output when patching
C:\Python27\python.exe C:/Development/python/http/hang.py
before conn.request
Internal error in evhttp
# Output when using regular python hhtplib
#C:\Python27\python.exe C:/Development/python/http/hang.py
#before conn.request
#Traceback (most recent call last):
# File "C:/Development/python/http/hang.py", line 14, in <module>
# conn.request("GET", url,headers=headers)
# File "C:\Python27\lib\httplib.py", line 941, in request
# self._send_request(method, url, body, headers)
# File "C:\Python27\lib\httplib.py", line 975, in _send_request
# self.endheaders(body)
# File "C:\Python27\lib\httplib.py", line 937, in endheaders
# self._send_output(message_body)
# File "C:\Python27\lib\httplib.py", line 797, in _send_output
# self.send(msg)
# File "C:\Python27\lib\httplib.py", line 759, in send
# self.connect()
# File "C:\Python27\lib\httplib.py", line 740, in connect
# self.timeout, self.source_address)
# File "C:\Python27\lib\socket.py", line 553, in create_connection
# for res in getaddrinfo(host, port, 0, SOCK_STREAM):
#socket.gaierror: [Errno 11004] getaddrinfo failed
#
#Process finished with exit code 1