From c42c8c6be0c3a163ed9a90d28642e008e36e9490 Mon Sep 17 00:00:00 2001 From: Jonathan Pevarnek Date: Thu, 24 Jan 2019 11:51:17 -0500 Subject: [PATCH] Handle httplib implementations that don't set _tunnel_host urllib3 removed support for Python versions before 2.7 in a previous pull request, unfortunately, this broke environments that use a different implementation of httplib than the one in Python's standard library as well. This includes Google App Engine's urlfetch-based implementation (https://github.com/GoogleCloudPlatform/python-compat-runtime/blob/master/appengine-compat/exported_appengine_sdk/google/appengine/dist27/gae_override/httplib.py#L362) This pull request is nearly identical to urllib3/urllib3#1504 which was closed due to its author not responding to comments. Fixes urllib3/urllib3#1503 --- src/urllib3/connection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py index 732def8e81..5afd3d404e 100644 --- a/src/urllib3/connection.py +++ b/src/urllib3/connection.py @@ -171,7 +171,8 @@ def _new_conn(self): def _prepare_conn(self, conn): self.sock = conn - if self._tunnel_host: + # Google App Engine's httplib does not define _tunnel_host + if getattr(self, '_tunnel_host', None): # TODO: Fix tunnel so it doesn't depend on self.sock state. self._tunnel() # Mark this connection as not reusable @@ -305,7 +306,8 @@ def connect(self): conn = self._new_conn() hostname = self.host - if self._tunnel_host: + # Google App Engine's httplib does not define _tunnel_host + if getattr(self, '_tunnel_host', None): self.sock = conn # Calls self._set_hostport(), so self.host is # self._tunnel_host below.