handle gzip for python27. Fixes #789 (#793)

This commit is contained in:
Nick Lang
2018-05-18 13:52:37 -06:00
committed by GitHub
parent 15a4d7e2cc
commit 206e0d609c
+7 -1
View File
@@ -161,7 +161,13 @@ class Urllib3HttpConnection(Connection):
request_headers = request_headers.copy()
request_headers.update(headers)
if self.http_compress and body:
body = gzip.compress(body)
try:
body = gzip.compress(body)
except AttributeError:
# oops, Python2.7 doesn't have `gzip.compress` let's try
# again
body = gzip.zlib.compress(body)
response = self.pool.urlopen(method, url, body, retries=False, headers=request_headers, **kw)
duration = time.time() - start
raw_data = response.data.decode('utf-8')