错误401和API V1.1 Python

时间:2016-08-18 17:51:15

标签: python api authentication tweepy

早上好, 我试图通过这个python代码下载在某个区域中某些单词的人:

import sys
import tweepy

consumer_key="LMhbj3fywfKPNgjaPhOwQuFTY"
consumer_secret="   LqMw9x9MTkYxc5oXKpfzvfbgF9vx3bleQHroih8wsMrIUX13nd"
access_key="3128235413-OVL6wctnsx1SWMYAGa5vVZwDH5ul539w1kaQTyx"
access_secret="fONdTRrD65ENIGK5m9ntpH48ixvyP2hfcJRqxJmdO78wC"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)

class CustomStreamListener(tweepy.StreamListener):
   def on_status(self, status):
       if 'busco casa' in status.text.lower():
           print (status.text)

def on_error(self, status_code):
    print (sys.stderr, 'Encountered error with status code:', status_code)
    return True # Don't kill the stream

def on_timeout(self):
    print (sys.stderr, 'Timeout...')
    return True # Don't kill the stream
sapi = tweepy.streaming.Stream(auth, CustomStreamListener()) 
sapi.filter(locations=[-78.37,-0.20,-78.48,-0.18])

我收到此错误: 遇到错误,状态代码为:401

我在此链接https://dev.twitter.com/overview/api/response-codes中读到该错误是由以下原因引起的: 身份验证凭据丢失或不正确。 在其他情况下也会返回,例如,对API v1端点的所有调用现在返回401(改为使用API​​ v1.1)。

使用更新的密钥进行身份验证。我该如何使用API​​ v1.1?

谢谢, 阿妮塔

1 个答案:

答案 0 :(得分:0)

如果它说您的凭据不正确,您可能需要检查您的凭据:您需要删除消费者机密中的空格,以使代码生效。

另外,我刚刚测试了你的凭据(没有空格)并且它们正在工作。我可以代表您的申请做任何我想做的事情。我建议你很快转到https://apps.twitter.com并生成新的。{3}}。切勿分享您的凭据。特别是在线,每个人都可以看到它们。