2012-05-21 64 views
2

嗨,我剛剛開始評估python> Twitter api:s的不同選項。Twython:運行示例的錯誤

我已經寫了一些代碼看Twython包中的例子,但我總是得到相同的錯誤。

AttributeError: 'Twython' object has no attribute 'auth' 

我也收到運行包含core_example文件相同的錯誤。

我從git運行「2.0.0」。

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /Users/skjortan/dev/trunk/3rdPartyLibs/twython/core_examples/current_trends.py 
Traceback (most recent call last): 
    File "/Users/skjortan/dev/trunk/3rdPartyLibs/twython/core_examples/current_trends.py", line 5, in <module> 
    trends = twitter.getCurrentTrends() 
    File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 167, in <lambda> 
    return lambda **kwargs: self._constructFunc(key, **kwargs) 
    File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 188, in _constructFunc 
    content = self._request(url, method=method, params=kwargs) 
    File "/Library/Python/2.7/site-packages/twython-2.0.0-py2.7.egg/twython/twython.py", line 205, in _request 
    response = func(url, data=myargs, auth=self.auth) 
AttributeError: 'Twython' object has no attribute 'auth' 

過程完成,退出代碼爲1

回答

2

我注意到你的問題 - 我Twython的作者。一個修補程序已被提交併推出2.0.1版本。如果你更新你的安裝,這應該不再是一個問題。

謝謝,對不起,麻煩!我們2.0.0版本發佈的漏洞。

0

但它真的有沒有屬性「權威性」,但它具有類似的方法:

def get_authentication_tokens(self): 
    """Returns an authorization URL for a user to hit.""" 

def get_authorized_tokens(self): 
    """Returns authorized tokens after they go through the auth_url phase.""" 

這是Django的twython樣本如何它的作者使auth

def begin_auth(request): 
    """ 
    The view function that initiates the entire handshake. 
    For the most part, this is 100% drag and drop. 
    """ 
    # Instantiate Twython with the first leg of our trip. 
    twitter = Twython(
    twitter_token = settings.TWITTER_KEY, 
    twitter_secret = settings.TWITTER_SECRET, 
    callback_url =  request.build_absolute_uri(reverse('twython_django_oauth.views.thanks'))) 

    # Request an authorization url to send the user to... 
    auth_props = twitter.get_authentication_tokens() 

    # Then send them over there, durh. 
    request.session['request_token'] = auth_props 
    return HttpResponseRedirect(auth_props['auth_url']) 
0

顯然twitter api和不允許正常登錄,只爲oauth,創建th從那裏Twitter和OAuth的設置選項卡有關電子應用需要從OAuth的設置數據,並在OAuth的方法:

http://pydoc.net/twython/1.4.5/twython.twitter_endpoints

+0

但基本搜索和獲取公共時間表不應該需要身份驗證。或者最近在twitter api中有過改變嗎? – Thom