【问题标题】:Tweepy: simple script with 'Bad Authentication data' errorTweepy:带有“错误身份验证数据”错误的简单脚本
【发布时间】:2013-12-21 22:48:11
【问题描述】:

这真的是身份验证问题还是与其他问题有关? 我必须修改什么才能消除错误?

#!/usr/bin/env python
import tweepy

ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'

auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

api = tweepy.API(auth)

results = tweepy.api.search(geocode='50,50,5mi')

for result in results:
    print result.text
    print result.location if hasattr(result, 'location') else "Undefined location"

这是我得到的错误

C:\Python27\python.exe C:/untitled/testfile.py
Traceback (most recent call last):
  File "C:/untitled/testfile.py", line 18, in <module>
    results = tweepy.api.search(geocode='50,50,5mi')
  File "build\bdist.win-amd64\egg\tweepy\binder.py", line 197, in _call
  File "build\bdist.win-amd64\egg\tweepy\binder.py", line 173, in execute
tweepy.error.TweepError: [{u'message': u'Bad Authentication data', u'code': 215}]

【问题讨论】:

    标签: python twitter tweepy


    【解决方案1】:

    你做错了:

    应该是-

    #!/usr/bin/env python
    import tweepy
    
    ckey = 'xxx'
    csecret = 'xxx'
    atoken = 'xxx'
    asecret = 'xxx'
    
    auth = tweepy.OAuthHandler(ckey, csecret)
    auth.set_access_token(atoken, asecret)
    
    api = tweepy.API(auth)
    
    # here's where you went wrong (tried and tested), should be
    #results = api.search(geocode='50,50,5mi')
    # try with the following lat long
    results = api.search(geocode='39.833193,-94.862794,5mi') 
    
    for result in results:
        print result.text
        print result.location if hasattr(result, 'location') else "Undefined location"
    

    【讨论】:

    • 谢谢。这有助于消除错误。但我没有打印出任何结果。
    • 您的坐标完成了这项工作。谢谢。但是为什么它不适用于我的坐标?我尝试了其他坐标并得到与以前相同的结果:无。
    • 我不太确定为什么!但是你提供的坐标真的存在吗?
    • 是的,它们存在。我在纽约 (40.7144, -74.0060) 进行了尝试。没有结果!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2017-03-25
    • 2018-06-19
    • 2017-10-13
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    相关资源
    最近更新 更多