Tweepy 使用 python 3.4 访问 Twitter 流媒体 API



我无法使用tweepy访问Twitter流媒体API,使用以下示例代码使用python 3.4。此代码使用 python 2.4 运行。怎么了?

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener

ckey = ''
csecret = ''
atoken = ''
asecret = ''
class listener(StreamListener):
    def on_data(self, data):
        print (data)
        return True
    def on_error(self, status):
        print (status)
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["obama"])

你的代码完全正确。

但在 Windows Vista/7 上,使用 UAC,管理员帐户默认以非特权模式运行程序。或者,您可能正在尝试在当前用户帐户无权绑定到的端口上运行。运行以下代码以检测脚本是否具有管理员访问权限。

import ctypes
print ctypes.windll.shell32.IsUserAnAdmin()

如果它打印 1,那么它就可以了。如果为 0,则脚本没有管理员访问权限。

最新更新