首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twython:运行示例时出错

Twython:运行示例时出错
EN

Stack Overflow用户
提问于 2012-05-21 15:52:50
回答 3查看 1.1K关注 0票数 2

您好,我刚刚开始评估python>Twitter应用编程接口的不同选项。

我编写了一些代码来查看Twython包中的示例,但最终总是得到相同的错误。

代码语言:javascript
复制
AttributeError: 'Twython' object has no attribute 'auth'

运行包含的core_example文件时,我也得到相同的错误。

我正在运行git中的"2.0.0“。

代码语言:javascript
复制
/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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-05-24 17:17:57

我注意到你的问题了--我是Twython的作者。已提交并推出了2.0.1版本的修复。如果您更新您的安装,这应该不再是一个问题。

谢谢,很抱歉给您添了麻烦!在我们的2.0.0版本中出现的错误。

票数 2
EN

Stack Overflow用户

发布于 2012-05-21 15:57:27

但是它实际上没有'auth‘属性,但是它有这样的方法:

代码语言:javascript
复制
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的示例,它的作者如何进行身份验证

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2012-05-21 16:03:44

显然,twitter api和不允许正常登录,只是为了oauth,在Twitter设置选项卡上创建应用程序,从那里获取OAuth设置的数据,OAuth的方法在:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10681357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档