使用 Tweepy 检索 Twitter 数据时出现 401 错误 [英] 401 Error when retrieving Twitter data using Tweepy
本文介绍了使用 Tweepy 检索 Twitter 数据时出现 401 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Tweepy 检索 Twitter 数据,使用下面的代码,但我返回 401 错误,并且我重新生成访问令牌和秘密令牌,并且出现了相同的错误.
I am trying to retrieve Twitter data using Tweepy, using that below code, but I'm returning 401 error, and I regenerate the access and secret tokens, and the same error appeared.
#imports
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#setting up the keys
consumer_key = 'xxxxxxx'
consumer_secret = 'xxxxxxxx'
access_token = 'xxxxxxxxxx'
access_secret = 'xxxxxxxxxxxxx'
class TweetListener(StreamListener):
# A listener handles tweets are the received from the stream.
#This is a basic listener that just prints received tweets to standard output
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
#printing all the tweets to the standard output
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
stream = Stream(auth, TweetListener())
t = u"#سوريا"
stream.filter(track=[t])
推荐答案
只需重置系统时钟即可.
Just reset your system's clock.
如果用于身份验证的 API 请求来自声称其时间超出 Twitter 时间 15 分钟的服务器,则会失败并显示 401 错误.
If an API request to authenticate comes from a server that claims it is a time that is outside of 15 minutes of Twitter time, it will fail with a 401 error.
谢谢
这篇关于使用 Tweepy 检索 Twitter 数据时出现 401 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文