Tweepy: simple script with 'Bad Authentication data' error

别来无恙 提交于 2019-12-11 13:25:14

问题


Is this really an authentication problem or has it to do with something else? What do I have to modify to get rid of the error?

#!/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"

This is the error I get

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}]

回答1:


Your doing it wrong:

It should be-

#!/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"


来源:https://stackoverflow.com/questions/20717945/tweepy-simple-script-with-bad-authentication-data-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!