jplana / python-etcd

A python client for etcd
Other
520 stars 210 forks source link

Import urllib3 exception classes explicitly #221

Closed tiewei closed 7 years ago

tiewei commented 7 years ago

urllib3.exceptions module will be renamed as requests.packages.urllib3.exceptions when python-requests is loaded, when tries to catch urllib3.exceptions, it actually tries to catch requests.packages.urllib3.exceptions, at the same time urllib3 will always tries to throw exceptions with its own module name. As a result, no exceptions from urllib3 will be treated correctly (e.g. failed on reconnect). This commit imports urllib3 exception classes explicitly, so when tries to compare exception, it will always compares with the one from the same module.

tiewei commented 7 years ago

some e.g. proves the problem

-bash-4.2# python
Python 2.7.5 (default, Aug 29 2016, 10:12:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> import requests
>>> urllib3.exceptions.HTTPError.__module__
'requests.packages.urllib3.exceptions'
>>> from urllib3.exceptions import HTTPError
>>> HTTPError.__module__
'urllib3.exceptions'
>>> urllib3.__version__
'1.10.2'
>>> requests.__version__
'2.6.0'
coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.02%) to 88.462% when pulling 3eb214603b858b215a0498bdc96d3c7db27b832a on TieWei:urllib3_import into 0d0145f5e835aa032c97a0a5e09c4c68b7a03f66 on jplana:master.

ashcrow commented 7 years ago

:+1: Looks good to me.

juledwar commented 7 years ago

+1

vhosakot commented 7 years ago

👍 great catch!