【问题标题】:401 error on the terminal when trying to access the twitter api尝试访问 twitter api 时终端出现 401 错误
【发布时间】:2017-01-21 16:55:32
【问题描述】:

我的代码在 python 中如下所示,我一直收到此错误。

#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#Variables that contains the user credentials to access Twitter API 
consumer_key = ''
consumer_secret = ''
access_token = ''
access_secret = ''


#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):

    def on_data(self, data):
        print data
        return True

    def on_error(self, status):
        print status


if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords: 'python', 'javascript', 'ruby'
    stream.filter(track=['python', 'javascript', 'ruby'])

我在此链接上关注本教程,了解如何从 twitter 挖掘数据并在此基础上进行一些分析。 错误是这样的

samuel@samuel-Satellite-C850-B908:~/twitter_demo$ python twitter_streaming.py
401
401
401
401
401
401
401

它会逐行打印 401。问题是什么?谁能帮帮我?

【问题讨论】:

  • 查找 HTTP 错误 401

标签: python twitter tweepy


【解决方案1】:

检查您的系统时间,如果需要,将其更新/与全球时间服务器同步。如果您的系统关闭几分钟,Twitter 经常会抛出 401 Unauthorized。

编辑:PS - 我假设你有有效的访问令牌!

【讨论】:

    猜你喜欢
    • 2013-06-21
    • 2012-10-27
    • 2013-05-17
    • 2012-05-12
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    相关资源
    最近更新 更多