def _handle_response(self, req, uri, arg_data):
try:
handle = urllib_request.urlopen(req)
- if handle.info().get('Content-Encoding') == 'gzip':
+ if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']:
+ return handle
++ elif handle.info().get('Content-Encoding') == 'gzip':
+ # Handle gzip decompression
+ buf = StringIO(handle.read())
+ f = gzip.GzipFile(fileobj=buf)
+ data = f.read()
+ else:
+ data = handle.read()
+
if "json" == self.format:
- res = json.loads(handle.read().decode('utf8'))
+ res = json.loads(data.decode('utf8'))
return wrap_response(res, handle.headers)
else:
return wrap_response(