Bug 1313465

Summary: urllib3 throwing exception when trying to str(err)
Product: Red Hat Enterprise Linux 7 Reporter: Joel Diaz <jdiaz>
Component: python-urllib3Assignee: Python Maintainers <python-maint>
Status: CLOSED WORKSFORME QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.2CC: cstratak, jberan, jdiaz, jkejda, twiest
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-17 16:44:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joel Diaz 2016-03-01 16:14:56 UTC
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 11:12:21 UTC
This was fixed in upstream by following patch:

https://github.com/Lukasa/urllib3/commit/6e7ae92b16ae365ce3b3bacb19dddab457657a9e

Comment 7 Charalampos Stratakis 2017-01-13 17:14:10 UTC
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 17:13:15 UTC
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 10:11:24 UTC
So the issue is fixed actually? Can the bug be closed?

Comment 10 Joel Diaz 2017-01-17 15:04:38 UTC
(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.