Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #36 from phrawzty/g_to_the_zip
Browse files Browse the repository at this point in the history
decompress gzip response when fetching batch info blob
  • Loading branch information
phrawzty authored Jun 24, 2017
2 parents b3c2298 + 3a7cca9 commit 5324c6e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Contents/Code/audioaddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,20 @@ def get_batchinfo(self, refresh=False):

req = urllib2.Request(url)
req.add_header(*self.authheader)
data = urllib2.urlopen(req).read()
# AA started gzip compressing (just) this response in June 2017.
req.add_header('Accept-Encoding', 'gzip')

response = urllib2.urlopen(req)

# This may or may not be a permanent change, so we'll wrap this in a
# conditional for now. Also, if other endpoints start returning gzip'd
# data, this should be implemented more generically. OK for today tho.
if response.info().get('Content-Encoding') == 'gzip':
from StringIO import StringIO
import gzip
buf = StringIO(response.read())
obj = gzip.GzipFile(fileobj=buf)
data = obj.read()

batch = json.loads(data)

Expand Down

0 comments on commit 5324c6e

Please sign in to comment.