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

decompress gzip response when fetching batch info blob #36

Merged
merged 1 commit into from
Jun 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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