我正在运行以下程序。但是正在收到以下错误消息。
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'])

最佳答案

这就是它的工作方式.. !!!

  • Twitter跟踪当前时间。
  • 如果身份验证的API请求来自声称其时间不超过Twitter时间15分钟的服务器,则它将失败并显示401错误。

  • 只需根据世界时钟重设系统时钟,或让它由互联网控制,即可解决问题。

    祝你好运..!!!

    关于python-2.7 - 使用tweepy时出现401错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26827790/

    10-12 20:16