2

嗨,我刚刚开始评估 python>Twitter api:s 的不同选项。

我已经编写了一些代码来查看 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 结束

4

3 回答 3

2

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

谢谢,打扰了!我们的 2.0.0 版本中出现的错误。

于 2012-05-24T09:17:57.313 回答
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 的示例,其作者如何进行身份验证

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-21T07:57:26.950 回答
0

显然 twitter api 并且不允许正常登录,仅用于 oauth,在 Twitter 和 OAuth 设置选项卡上创建应用程序,从那里获取来自 OAuth 设置的数据,以及 oauth 的方法:

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

于 2012-05-21T08:03:44.243 回答