api = twitter.Api() AttributeError: 'module' 对象没有属性 'Api [英] api = twitter.Api() AttributeError: 'module' object has no attribute 'Api
问题描述
我一直在尝试编写一个简单的提及抓取器来开始使用 twitter Api.然而,我在初始化 Api 时遇到了一些困难.在 archlinux 上运行 python2 我通过 easy_install 安装了 twitter,从源代码构建它并通过 pip 安装它.这些似乎都不起作用.
zergling :: ~/dev/kritter » python2Python 2.7.2(默认,2012 年 1 月 31 日,13:26:35)[GCC 4.6.2 20120120 (prerelease)] 在 linux2输入帮助"、版权"、信用"或许可"以获取更多信息.>>>导入推特>>>api = twitter.api()回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中AttributeError: 'module' 对象没有属性 'Api'
无论如何 twitter 的 pydoc 都在那里.我不知道我做错了什么.希望能帮到你
更新:我尝试使用 twitter.api()
而不是 twitter.Api()
并得到以下错误:回溯(最近一次调用最后一次):文件main.py",第 8 行,在api = twitter.api()类型错误:模块"对象不可调用
附加信息:
<预><代码>>>>打印目录(推特)['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']>>>打印 twitter.__path__['/usr/lib/python2.7/site-packages/twitter-1.7.2-py2.7.egg/twitter']我想您已经安装了一个 twitter 包,并查看了另一个文档.即:python-1.7.2 是来自 https://github.com/sixohsix/twitter 的项目,当您查看 http://code.google.com/p/python-twitter/时/ 文档.两者之间不匹配:)
所以对于你安装的那个,如果你检查源代码,一个 流示例 可用,pydoc 中还有其他各种示例:
from twitter import Twitter# ...推特 = 推特(auth=OAuth(token, token_key, con_secret, con_secret_key)))# 获取公共时间线twitter.statuses.public_timeline()
I have been trying to write a simple mention grabber to get started with the twitter Api. Howsoever I've been experienceing some difficulties when initializing the Api. Running python2 on archlinux I installed twitter via easy_install, built it from source and installed it via pip. None of this seems to be working.
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'
Howsoever the pydoc for twitter is there. I have no clue what I'm doing wrong. I hope you can help
UPDATE:
I tried using twitter.api()
instead of twitter.Api()
and got the following error:
Traceback (most recent call last):
File "main.py", line 8, in
api = twitter.api()
TypeError: 'module' object is not callable
Additional Informations:
>>> 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']
I think you've installed one twitter package, and look at another documentation. Ie: python-1.7.2 is the project from https://github.com/sixohsix/twitter, while you're looking at the http://code.google.com/p/python-twitter/ documentation. No match between both :)
So for the one you've installed, if you check the source code, a stream example is available, and other various examples in the pydoc:
from twitter import Twitter
# ...
twitter = Twitter(
auth=OAuth(token, token_key, con_secret, con_secret_key)))
# Get the public timeline
twitter.statuses.public_timeline()
这篇关于api = twitter.Api() AttributeError: 'module' 对象没有属性 'Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!