Bug 1313465 - urllib3 throwing exception when trying to str(err)
urllib3 throwing exception when trying to str(err)
Status: CLOSED WORKSFORME
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: python-urllib3 (Show other bugs)
7.2
x86_64 Linux
unspecified Severity medium
: rc
: ---
Assigned To: Python Maintainers
BaseOS QE - Apps
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-03-01 11:14 EST by Joel Diaz
Modified: 2017-01-17 11:44 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-01-17 11:44:44 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Joel Diaz 2016-03-01 11:14:56 EST
Description of problem:
Trying to connect with urllib3's built-in pyopenssl to a dead URL results in an unexpected exception.


Version-Release number of selected component (if applicable):
python-urllib3-1.10.2-2.el7_1.noarch

How reproducible:
100%

Steps to Reproduce:
1. Try a simple script to connect to a non-running URL.

2. #!/usr/bin/python

import urllib3
from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()

http = urllib3.PoolManager()
http.request('GET', 'https://localhost/')

Actual results:
[CTR][root@9a3e220a0a39 site-packages]$ /root/python-test.py
Traceback (most recent call last):
  File "/root/python-test.py", line 8, in <module>
    http.request('GET', 'https://localhost/')
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request
    **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url
    return self.urlopen(method, url, **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 161, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 545, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 345, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 315, in _raise_timeout
    if 'timed out' in str(err) or 'did not complete (read)' in str(err):  # Python 2.6
TypeError: __str__ returned non-string (type Error)


Expected results:
When using non-urllib3-pyopenssl (ie no inject_info_urllib3() call), you get: urllib3.exceptions.SSLError: [Errno 2] No such file or directory

Additional info:
Comment 2 Robert Kuska 2016-03-09 06:12:21 EST
This was fixed in upstream by following patch:

https://github.com/Lukasa/urllib3/commit/6e7ae92b16ae365ce3b3bacb19dddab457657a9e
Comment 7 Charalampos Stratakis 2017-01-13 12:14:10 EST
Can't reproduce with python-urllib3-1.10.2-2.el7_1.noarch as the error message I get is:

Traceback (most recent call last):
  File "./python-test.py", line 8, in <module>
    http.request('GET', 'https://localhost/')
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request
    **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url
    return self.urlopen(method, url, **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 161, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen
    release_conn=release_conn, **response_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 597, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python2.7/site-packages/urllib3/util/retry.py", line 271, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localhost', port=443): Max retries exceeded with url: / (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))
Comment 8 Joel Diaz 2017-01-16 12:13:15 EST
I'm seeing the expected (fixed) behavior:

[CTR][root@f4fb8924a8dc ~]$ rpm -qa | grep urllib
python-urllib3-1.10.2-2.el7_1.noarch
[CTR][root@f4fb8924a8dc ~]$ python
Python 2.7.5 (default, Aug  2 2016, 04:20:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> from urllib3.contrib import pyopenssl                                                                                                                        
>>> pyopenssl.inject_into_urllib3()
>>> http = urllib3.PoolManager()
>>> http.request('GET', 'https://localhost/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request
    **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url
    return self.urlopen(method, url, **urlopen_kw)
  File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 161, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 574, in urlopen
    raise SSLError(e)
urllib3.exceptions.SSLError
Comment 9 Charalampos Stratakis 2017-01-17 05:11:24 EST
So the issue is fixed actually? Can the bug be closed?
Comment 10 Joel Diaz 2017-01-17 10:04:38 EST
(In reply to Charalampos Stratakis from comment #9)
> So the issue is fixed actually? Can the bug be closed?

Yep. The original problem is fixed.

Note You need to log in before you can comment on or make changes to this bug.