Skip to content

Commit

Permalink
Do not send gzip header for streaming calls
Browse files Browse the repository at this point in the history
Twitter is moving all of its APIs towards HTTP1.1.
https://dev.twitter.com/blog/deprecating-http-1.0-streaming-api
Userstream passed already mid-november and has been borken for this lib since
On Jan 6, Twitter will apply it as weel for all the other stream methods,
meaning they probably would be all broken.

The problem was in two pieces.
First with this commit, we stop asking for gzip encoded data for streaming
calls: for the HTPP1.0 calls, this was not taken into account anyway, but with
HTTP1.1 the answer is now chunked and should therefore not caught zipped.

(First part of fix for userstream and soon all streams cf python-twitter-tools#190 python-twitter-tools#116)
  • Loading branch information
RouxRC committed Dec 27, 2013
1 parent 31dd1a0 commit 73efaca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions twitter/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TwitterCall(object):

def __init__(
self, auth, format, domain, callable_cls, uri="",
uriparts=None, secure=True, timeout=None):
uriparts=None, secure=True, timeout=None, gzip=False):
self.auth = auth
self.format = format
self.domain = domain
Expand All @@ -137,6 +137,7 @@ def __init__(
self.uriparts = uriparts
self.secure = secure
self.timeout = timeout
self.gzip = gzip

def __getattr__(self, k):
try:
Expand All @@ -147,7 +148,7 @@ def extend_call(arg):
auth=self.auth, format=self.format, domain=self.domain,
callable_cls=self.callable_cls, timeout=self.timeout, uriparts=self.uriparts \
+ (arg,),
secure=self.secure)
secure=self.secure, gzip=self.gzip)
if k == "_":
return extend_call
else:
Expand Down Expand Up @@ -194,7 +195,9 @@ def __call__(self, **kwargs):
uriBase = "http%s://%s/%s%s%s" %(
secure_str, self.domain, uri, dot, self.format)

headers = {'Accept-Encoding': 'gzip'}
headers = {}
if self.gzip:
headers['Accept-Encoding'] = 'gzip'
if self.auth:
headers.update(self.auth.generate_headers())
arg_data = self.auth.encode_params(uriBase, method, kwargs)
Expand Down
2 changes: 1 addition & 1 deletion twitter/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ def __init__(
TwitterStreamCall.__init__(
self, auth=auth, format="json", domain=domain,
callable_cls=call_cls,
secure=secure, uriparts=uriparts, timeout=timeout)
secure=secure, uriparts=uriparts, timeout=timeout, gzip=False)

0 comments on commit 73efaca

Please sign in to comment.