您好我刚刚开始评估python的各种选项> Twitter api:s。
我已经编写了一些代码来查看Twython包中的示例,但我总是得到同样的错误。
AttributeError: 'Twython' object has no attribute 'auth'
运行包含的core_example文件时也会遇到同样的错误。
我正在跑步" 2.0.0"来自git。
/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完成处理
答案 0 :(得分:2)
我注意到你的问题 - 我是Twython的作者。修复已提交并推出2.0.1版本。如果您更新安装,这应该不再是一个问题。
谢谢,抱歉麻烦!我们的2.0.0版本漏掉了这个漏洞。
答案 1 :(得分:0)
但它确实没有属性'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的样本作者如何制作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'])
答案 2 :(得分:0)
显然是twitter api并且不允许正常登录,只是为了oauth,在Twitter和OAuth设置选项卡上创建应用程序从那里获取来自OAuth设置的数据和oauth的方法: