From: Joshua Roesslein Date: Fri, 20 Nov 2009 06:04:52 +0000 (-0600) Subject: Move parameters into POST body in streaming.py to avoid "head too big" errors. Thanks... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eb1d8bb89c524af9e6fa0d298f352bc5d59223e8;p=tweepy.git Move parameters into POST body in streaming.py to avoid "head too big" errors. Thanks Pascal! --- diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 35a8538..c0ece3e 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -6,6 +6,7 @@ import httplib from socket import timeout from threading import Thread from time import sleep +import urllib from tweepy.auth import BasicAuthHandler from tweepy.parsers import parse_status @@ -64,11 +65,12 @@ class Stream(object): self.buffer_size = buffer_size self.listener = listener self.api = API() + self.headers = {} + self.body = None def _run(self): # setup - headers = {} - self.auth.apply_auth(None, None, headers, None) + self.auth.apply_auth(None, None, self.headers, None) # enter loop error_counter = 0 @@ -81,7 +83,7 @@ class Stream(object): conn = httplib.HTTPConnection(self.host) conn.connect() conn.sock.settimeout(self.timeout) - conn.request('POST', self.url, headers=headers) + conn.request('POST', self.url, self.body, headers=self.headers) resp = conn.getresponse() if resp.status != 200: if self.listener.on_error(resp.status) is False: @@ -168,13 +170,16 @@ class Stream(object): Thread(target=self._run).start() def filter(self, follow=None, track=None): + params = {} + self.headers['Content-type'] = "application/x-www-form-urlencoded" if self.running: raise TweepError('Stream object already connected!') self.url = '/%i/statuses/filter.json?delimited=length' % STREAM_VERSION if follow: - self.url += '&follow=%s' % ','.join(follow) + params['follow'] = ','.join(map(str, follow)) if track: - self.url += '&track=%s' % ','.join(track) + params['track'] = ','.join(map(str, track)) + self.body = urllib.urlencode(params) self.running = True Thread(target=self._run).start()