【问题标题】:Tweepy to access Twitter streaming API using python 3.4Tweepy 使用 python 3.4 访问 Twitter 流 API
【发布时间】:2015-03-06 23:19:15
【问题描述】:

我无法使用 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"])

【问题讨论】:

    标签: twitter tweepy


    【解决方案1】:

    您的代码完全正确。

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

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

    如果它打印 1 则没问题。如果为 0,则您的脚本没有管理员权限。

    【讨论】:

      猜你喜欢
      • 2015-12-31
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2016-11-08
      相关资源
      最近更新 更多