我尝试使用Twitter streaming API
(和python 3)简单地连接到tweepy
,然后流式传输来自给定单个用户的所有推文。
我认为这是可能的,所以我有以下简单的代码来执行此操作:
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'])
当我从命令行运行它时,我只是从Twitter获得了一堆406代码。我是如何尝试使用tweepy的,或者是"关注"参数不是为了做我认为的那样吗?
编辑:我还在费城的讨论板上发布了this。
答案 0 :(得分:7)
我能够使用Tweepy 3.2.0在Python 3.4上重现您的问题。升级到3.3.0解决了这个问题:
$ 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",
[...]
Tweepy 3.3.0 Changelog提到了几项流媒体改进,但我没有看到他们提到的“冻结”问题。