Twitter 模块 python 'module' 对象没有属性 Oauth [英] Twitter module python 'module' object has no attribute Oauth
本文介绍了Twitter 模块 python 'module' 对象没有属性 Oauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试遵循这个基本示例 这里.
Im trying to follow this basic example here.
代码
import twitter
# XXX: Go to http://dev.twitter.com/apps/new to create an app and get values
# for these credentials, which you'll need to provide in place of these
# empty string values that are defined as placeholders.
# See https://dev.twitter.com/docs/auth/oauth for more information
# on Twitter's OAuth implementation.
CONSUMER_KEY = ''
CONSUMER_SECRET =''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
CONSUMER_KEY, CONSUMER_SECRET)
twitter_api = twitter.Twitter(auth=auth)
# Nothing to see by displaying twitter_api except that it's now a
# defined variable
print twitter_api
但是运行该示例会引发以下错误.
But running the example throws the following error.
vagrant@lucid32:~$ python twitter.py
Traceback (most recent call last):
File "twitter.py", line 1, in <module>
import twitter
File "/home/vagrant/twitter.py", line 14, in <module>
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
AttributeError: 'module' object has no attribute 'oauth'
任何帮助将不胜感激.
推荐答案
不要将脚本命名为与导入的模块相同的名称,因为当 python 导入时,它首先在脚本目录中查找,所以 twitter.py
被导入而不是 twitter
模块.
Don't name your scripts the same as modules you're import, as when python imports it first looks in script directory, so twitter.py
is imported instead of twitter
module.
并且在您使用 twitter.py
将文件重命名为不同的名称后,不要忘记删除它的编译代码(twitter.pyc
和 tweepy.pyc
).
And after you rename your file to something different with twitter.py
, don't forget to remove it's compiled code (twitter.pyc
and tweepy.pyc
).
这篇关于Twitter 模块 python 'module' 对象没有属性 Oauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文