Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gevent 1.1a2 TypeError during socket error handling after monkey.patch_socket() on Windows #628

Closed
jacekt opened this issue Aug 1, 2015 · 4 comments
Labels
PyVer: python3 Affects Python 3

Comments

@jacekt
Copy link

jacekt commented Aug 1, 2015

gevent 1.1a2, requests 2.7.0, Python 3.4.3 on Windows

STEPS TO REPRODUCE:

> py -3 -c "import gevent.monkey; gevent.monkey.patch_socket(); import requests; requests.get('http://1.2.3.4/')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 349, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python34\lib\http\client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "C:\Python34\lib\http\client.py", line 1126, in _send_request
    self.endheaders(body)
  File "C:\Python34\lib\http\client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "C:\Python34\lib\http\client.py", line 922, in _send_output
    self.send(msg)
  File "C:\Python34\lib\http\client.py", line 857, in send
    self.connect()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 155, in connect
    conn = self._new_conn()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 134, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.py", line 78, in create_connection
    sock.connect(sa)
  File "C:\Python34\lib\site-packages\gevent\_socket3.py", line 252, in connect
    raise error(err, strerror(err))
  File "C:\Python34\lib\site-packages\gevent\win32util.py", line 89, in formatError
    return self.winError(errorcode)[1]
TypeError: 'TimeoutError' object is not subscriptable

Any kind of win socket error in this place will fail the same way, not only TimeoutError - I've seen also:
TypeError: 'ConnectionRefusedError' object is not subscriptable
TypeError: 'OSError' object is not subscriptable

Without monkey patching it works correctly (ultimately requests.exceptions.ConnectionError raised):

> py -3 -c "import requests; requests.get('http://1.2.3.4/')"
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 349, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python34\lib\http\client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "C:\Python34\lib\http\client.py", line 1126, in _send_request
    self.endheaders(body)
  File "C:\Python34\lib\http\client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "C:\Python34\lib\http\client.py", line 922, in _send_output
    self.send(msg)
  File "C:\Python34\lib\http\client.py", line 857, in send
    self.connect()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 155, in connect
    conn = self._new_conn()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 134, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.py", line 88, in create_connection
    raise err
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.py", line 78, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 597, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 309, in reraise
    raise value.with_traceback(tb)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 349, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "C:\Python34\lib\http\client.py", line 1088, in request
    self._send_request(method, url, body, headers)
  File "C:\Python34\lib\http\client.py", line 1126, in _send_request
    self.endheaders(body)
  File "C:\Python34\lib\http\client.py", line 1084, in endheaders
    self._send_output(message_body)
  File "C:\Python34\lib\http\client.py", line 922, in _send_output
    self.send(msg)
  File "C:\Python34\lib\http\client.py", line 857, in send
    self.connect()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 155, in connect
    conn = self._new_conn()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connection.py", line 134, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.py", line 88, in create_connection
    raise err
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\connection.py", line 78, in create_connection
    sock.connect(sa)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
@jamadden
Copy link
Member

jamadden commented Aug 3, 2015

I believe this is fixed with 39ea1cb. Can you retry with current master?

@jamadden jamadden added the PyVer: python3 Affects Python 3 label Aug 3, 2015
@jacekt
Copy link
Author

jacekt commented Aug 3, 2015

Works better. [Note: I've tested only this single changeset applied against 1.1a2, as I can't compile gevent master with mingw, and don't have vc++ handy.]

The only thing is that slightly different exception is raised.

Without monkey patching:
$ py -3 -c "import requests; requests.get('http://1.2.3.4/')"
[...]
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))

With monkey patching:
$ py -3 -c "import gevent.monkey; gevent.monkey.patch_socket(); import requests; requests.get('http://1.2.3.4/')"
[...]
requests.exceptions.ConnectionError: ('Connection aborted.', TimeoutError(10060, '[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.'))

I don't care about this difference, but maybe somebody does.

@jamadden
Copy link
Member

jamadden commented Aug 3, 2015

Thank you for your report. Since it looks like the TypeError is gone, and the basic types of the raised errors are all correct and only some trailing arguments differ, I'm going to go ahead and close this. If someone runs into a case where that matters, please feel free to open a specific bug about that.

@jamadden jamadden closed this as completed Aug 3, 2015
@jamadden
Copy link
Member

jamadden commented Aug 3, 2015

FWIW, if it helps, you can now grab pre-built wheel files for most any commit for 32 and 64-bit windows by following the links to a (green) build on https://ci.appveyor.com/project/denik/gevent/history, finding the appropriate bitness, and clicking the Artifacts tab.

hashbrowncipher pushed a commit to hashbrowncipher/gevent that referenced this issue Oct 20, 2018
* gevent#544 tox --version shows registered plugins now

* add news fragment

* make easier to test and add tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PyVer: python3 Affects Python 3
Projects
None yet
Development

No branches or pull requests

2 participants