【发布时间】:2012-03-06 15:52:10
【问题描述】:
我一直在尝试编写一个简单的提及抓取器来开始使用 twitter Api。然而,我在初始化 Api 时遇到了一些困难。 在archlinux上运行python2我通过easy_install安装了twitter,从源代码构建它并通过pip安装它。这些似乎都不起作用。
zergling :: ~/dev/kritter » python2
Python 2.7.2 (default, Jan 31 2012, 13:26:35)
[GCC 4.6.2 20120120 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import twitter
>>> api = twitter.Api()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Api'
不管 twitter 的 pydoc 在那里。我不知道我做错了什么。希望能帮到你
更新:
我尝试使用 twitter.api() 而不是 twitter.Api() 并收到以下错误:
回溯(最近一次通话最后):
文件“main.py”,第 8 行,在
api = twitter.api()
TypeError: 'module' 对象不可调用
其他信息:
>>> print dir(twitter)
['NoAuth', 'OAuth', 'Twitter', 'TwitterError', 'TwitterHTTPError', 'TwitterResponse', 'TwitterStream', 'UserPassAuth', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'api', 'auth', 'oauth', 'read_token_file', 'stream', 'twitter_globals', 'write_token_file']
>>> print twitter.__path__
['/usr/lib/python2.7/site-packages/twitter-1.7.2-py2.7.egg/twitter']
【问题讨论】:
-
尝试“print dir(twitter)”和“print twitter.__path__”,可以看到模块中可用的方法是什么,以及它的位置(确保你使用的是正确的.)
-
@tito:从中得到以下信息。使用 twitter.api() 我收到另一个错误:
api = twitter.api(); TypeError: 'module' object is not callable -
好吧,你看到他们在 dir() 中没有 Api 或 api 类/函数
-
我确定您没有为该模块寻找正确的文档。有很多 twitter python 包装器,看起来这个是不同的:)
-
twitter-1.7.2 和code.google.com/p/python-twitter 不一样,所以不要看那个文档,它是一个不同的项目
标签: python api twitter archlinux