2013-12-21 43 views
1

這是一個真正的身份驗證問題還是與其他問題有關? 我必須修改哪些內容才能擺脫錯誤?Tweepy:帶有'Bad Authentication data'錯誤的簡單腳本

#!/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}] 

回答

2

你就錯了:

應該是─

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

謝謝。這有助於消除錯誤。但我沒有得到任何結果打印出來。 – spamup

+0

檢查更新的答案! –

+0

你的座標完成了這項工作。謝謝。但爲什麼它不適合我的座標?我嘗試了其他座標並獲得與以前相同的結果:無。 – spamup