Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET request resulting in VerifiedHTTPSConnection object has no attribute '_tunnel_host'

I am using the python requests library to make a HTTP GET requests to an API hosted on GAE. Requests version is requests==2.20.0 and installed via pip using a virtual environment.

The issue has been reported to be caused by an outdated version of python, I am running the very latest version of python 2 (2.7.15).

Here is the code snipped:

endpoint_url = API_URL + "some/endpoint/%s" % some_variable
response = requests.get(url=endpoint_url)
return response.text

And here is the stackstace:

Traceback (most recent call last):
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/flask/app.py", line 2292, in 
wsgi_app
response = self.full_dispatch_request()
File "/Users/rhys/Desktop/Projects/git-r 
repositories/MitigatingCircumstancesTracker/lib/flask/app.py", line 1815, in 
full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/flask/app.py", line 1718, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/flask/app.py", line 1813, in 
full_dispatch_request
rv = self.dispatch_request()
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/flask/app.py", line 1799, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/main.py", line 83, in login
response = requests.get(url=endpoint_url)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/requests/api.py", line 75, in 
get
return request('get', url, params=params, **kwargs)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/requests/api.py", line 60, in 
request
return session.request(method=method, url=url, **kwargs)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/requests/sessions.py", line 
524, in request
resp = self.send(prep, **send_kwargs)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/requests/sessions.py", line 
637, in send
r = adapter.send(request, **kwargs)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/requests/adapters.py", line 
449, in send
timeout=timeout
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/urllib3/connectionpool.py", 
line 600, in urlopen
chunked=chunked)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/urllib3/connectionpool.py", 
line 343, in _make_request
self._validate_conn(conn)
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/urllib3/connectionpool.py", 
line 839, in _validate_conn
conn.connect()
File "/Users/rhys/Desktop/Projects/git- 
repositories/MitigatingCircumstancesTracker/lib/urllib3/connection.py", line 
304, in connect
if self._tunnel_host:
AttributeError: 'VerifiedHTTPSConnection' object has no attribute 
'_tunnel_host'

Python version from 'python --version' 2.7.15

requirements.txt:

bcrypt==3.1.4
certifi==2018.10.15
cffi==1.11.5
chardet==3.0.4
Click==7.0
Flask==1.0.2
idna==2.7
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pycparser==2.19
requests==2.20.0
six==1.11.0
urllib3==1.24
Werkzeug==0.14.1
like image 435
rhys_stubbs Avatar asked Dec 05 '22 10:12

rhys_stubbs


1 Answers

I had the same problem. In my case it was apparently related to Google App Engine's inability to work with requests in local development environment (with SDK). AppEngineAdapter requests_toolbelt is needed. Worked for me after.

like image 182
Eric Avatar answered Jan 04 '23 05:01

Eric