I'm trying to simply connect to the Twitter streaming API
using tweepy
(and python 3), and stream all tweets from a given single user.
I was under the impression this is possible, so I have the following simple code to do this:
from tweepy import StreamListener
from tweepy import Stream
import tweepy
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
class StdOutListener(StreamListener):
def on_data(self, data):
# process stream data here
print(data)
def on_error(self, status):
print(status)
if __name__ == '__main__':
listener = StdOutListener()
twitterStream = Stream(auth, listener)
twitterStream.filter(follow=['575930104'])
When I run this from the command line, I just get back a bunch of 406 codes from Twitter. Is there something very obviously wrong with how I am trying to use tweepy, or is the "follow" parameter not designed to do what I think it does?
EDIT: I've also posted this on the tweepy discussion boards, FYI.
I was able to reproduce your problem on Python 3.4 using Tweepy 3.2.0. Upgrading to 3.3.0 solved the problem:
$ bin/pip install -U tweepy==3.2.0
[...]
Successfully installed tweepy requests-oauthlib six requests
Cleaning up...
$ bin/python test.py
406
^CTraceback (most recent call last):
[...]
KeyboardInterrupt
$ bin/pip install -U tweepy==3.3.0
[...]
Successfully installed tweepy requests requests-oauthlib six
Cleaning up...
$ bin/python test.py
{"created_at":"Fri Feb 27 14:02:02 +0000 2015","id":571309283217768448,"id_str":"571309283217768448",
[...]
The Tweepy 3.3.0 Changelog mentions several streaming improvements, although I did not see the 'freezing' problem they mention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With