2012-11-16 19 views
1

我剛開始使用twython搜索,但在第一個例子:收到異常,當執行Twython

from twython import Twython 
t = Twython() 
t.search(q='python') 

我收到一個例外:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/twython-2.5.2-py2.7.egg/twython/twython.py", line 367, in search 
    return self.get('https://api.twitter.com/1.1/search/tweets.json', params=kwargs) 
    File "/usr/local/lib/python2.7/dist-packages/twython-2.5.2-py2.7.egg/twython/twython.py", line 238, in get 
    return self.request(endpoint, params=params, version=version) 
    File "/usr/local/lib/python2.7/dist-packages/twython-2.5.2-py2.7.egg/twython/twython.py", line 233, in request 
    content = self._request(url, method=method, params=params, files=files, api_call=url) 
    File "/usr/local/lib/python2.7/dist-packages/twython-2.5.2-py2.7.egg/twython/twython.py", line 210, in _request 
    retry_after=response.headers.get('retry-after')) 
twython.twython.TwythonError: 'Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. -- An error occurred processing your request.' 

不要任何人知道是什麼原因導致這例外?

感謝,

大號

回答

1

未經身份驗證的調用Twitter的API。 在這裏閱讀 - https://dev.twitter.com/docs/rate-limiting

+0

感謝您的回答,您能否提出解決方案,因爲我對這個問題很陌生。 –

+1

使用驗證? – alexvassel

+0

我想我找到了,謝謝。根據這個https://dev.twitter.com/docs/auth。訪問搜索API無需身份驗證,也許他們最近剛剛更改... –

0

core examples

from twython import Twython 

""" Instantiate Twython with no Authentication """ 
twitter = Twython() 
search_results = twitter.search(q="python", rpp="50") 

for tweet in search_results["results"]: 
    print "Tweet from @%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at']) 
    print tweet['text'].encode('utf-8'),"\n" 

我試過它和它的作品。

相關問題