【问题标题】:tweepy error.. Method doesn't existtweepy 错误.. 方法不存在
【发布时间】:2016-01-26 22:24:57
【问题描述】:

我需要运行 twitter api 调用以查找友谊。通话详情在这里:

https://dev.twitter.com/docs/api/1.1/get/friendships/lookup

我在 python 中使用 tweepy 来执行此操作,但是,它根本不存在于 tweepy 中。我做了一点挖掘,发现这个方法已经添加到 tweepy 并且我有最新版本。检查这个:

https://github.com/tweepy/tweepy/commit/aa055fe16c73f80a0a36279bfc83e40af3d93008

每当我尝试运行 api.lookup_friendship 时。它在代码中不存在。有什么办法可以让它工作吗?

【问题讨论】:

  • 你能确认python -c 'import tweepy; print tweepy.__version__'给你1.11吗?
  • @Martijn Pieters 另外一点,我在 mac osx 山狮上。 tweepy 的源文件在哪里?我可以从 git 中添加代码,不是吗?
  • 使用 bin/python -c 'import tweepy;打印 tweepy.__file__';我可以确认 1.11 缺少该方法,奇怪。
  • 能否贴出不起作用的示例代码?
  • @AndreBossard: import tweepy; api = tweepy.API(); api.lookup_friendships() -> AttributeError: 'API' object has no attribute 'lookup_friendships'。 1.11 发行版中包含的api.py 文件中没有定义这样的函数。

标签: python twitter tweepy


【解决方案1】:

您链接到的提交直到August 19th(在1.11 release was cut (on August 14th 2012) 之后)才与tweepy master 分支合并。在 1.12 发布之前,您需要直接从 git 安装才能获得此功能。*

要使用 pip 安装当前的开发版本,请使用:

pip install -e git+https://github.com/tweepy/tweepy.git#egg=tweepy

运行该命令后,.lookup_friendships() 方法就可用了:

>>> import tweepy
>>> api = tweepy.API()
>>> api.lookup_friendships
<bound method API.lookup_friendships of <tweepy.api.API object at 0x10a7ad290>>
>>> api.lookup_friendships()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/private/tmp/tweepy/src/tweepy/tweepy/api.py", line 285, in lookup_friendships
    return self._lookup_friendships(list_to_csv(user_ids), list_to_csv(screen_names))
  File "/private/tmp/tweepy/src/tweepy/tweepy/binder.py", line 184, in _call
    method = APIMethod(api, args, kargs)
  File "/private/tmp/tweepy/src/tweepy/tweepy/binder.py", line 34, in __init__
    raise TweepError('Authentication required!')
tweepy.error.TweepError: Authentication required!

我懒得登录;不过,上面的演示确实表明它有效。 :-)


* 1.12 版(包括此更改)于 2012 年 11 月 8 日发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 2015-04-30
    • 2021-12-18
    • 1970-01-01
    • 2012-08-21
    • 2017-06-04
    • 2019-08-04
    • 1970-01-01
    相关资源
    最近更新 更多