【问题标题】:401 error while using tweepy使用 tweepy 时出现 401 错误
【发布时间】:2015-01-05 19:28:57
【问题描述】:

我正在运行以下程序。但收到以下错误消息。 401**** 401**** (不断重复)

代码(从某个论坛获得)基本上尝试连接到 Twitter 并获取推文。 当它在 ubuntu 终端上运行时,会出现 401 错误消息。

import sys
import json
import pymongo
import tweepy
consumer_key="XX" ##all the keys and codes have to be strings
consumer_secret="XX"
access_token = "XX"
access_token_secret = "XX"
# This is the listener, resposible for receiving data

class StdOutListener(tweepy.StreamListener):

    def on_data(self, data):

        # Twitter returns data in JSON format - we need to decode it first

        decoded = json.loads(data)



        # Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users

        print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))

        print ''

        return True



    def on_error(self, status):

        print status



if __name__ == '__main__':

    l = StdOutListener()

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

    auth.set_access_token(access_token, access_token_secret)



    print "Showing all new tweets for #programming:"



    # There are different kinds of streams: public stream, user stream, multi-user streams

    # In this example follow #programming tag

    # For more details refer to https://dev.twitter.com/docs/streaming-apis

    stream = tweepy.Stream(auth, l)

    stream.filter(track=['programming'])

【问题讨论】:

  • 您使用的是正确的消费者/访问令牌,对吗?不只是来自“某个论坛”或"XX"的那些?
  • 我使用的是我从 twitter 开发者网站生成的正确的

标签: python-2.7 tweepy http-status-code-401


【解决方案1】:

这就是它的工作原理..!!!

  • Twitter 跟踪当前时间。
  • 如果用于身份验证的 API 请求来自声称其时间超出 Twitter 时间 15 分钟的服务器,则会失败并出现 401 错误。

只需根据世界时钟重置系统时钟或让它通过互联网管理您的问题将得到解决。

祝你好运..!!!

【讨论】:

  • 谢谢...我会试试...:-)
  • 你好,我如何在 Ubuntu 14.10 上做到这一点
  • 进入设置并根据全球时区设置您的时钟。
  • IMP:别忘了在你的推特账户中更改你的时区并验证你的电子邮件!其中之一对我有用
猜你喜欢
  • 2015-04-09
  • 1970-01-01
  • 2017-02-07
  • 2016-12-11
  • 2022-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多