您好,我刚刚开始评估python>Twitter应用编程接口的不同选项。
我编写了一些代码来查看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
发布于 2012-05-24 17:17:57
我注意到你的问题了--我是Twython的作者。已提交并推出了2.0.1版本的修复。如果您更新您的安装,这应该不再是一个问题。
谢谢,很抱歉给您添了麻烦!在我们的2.0.0版本中出现的错误。
发布于 2012-05-21 15:57:27
但是它实际上没有'auth‘属性,但是它有这样的方法:
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的示例,它的作者如何进行身份验证
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'])发布于 2012-05-21 16:03:44
显然,twitter api和不允许正常登录,只是为了oauth,在Twitter设置选项卡上创建应用程序,从那里获取OAuth设置的数据,OAuth的方法在:
http://pydoc.net/twython/1.4.5/twython.twitter_endpoints
https://stackoverflow.com/questions/10681357
复制相似问题