【发布时间】:2014-03-11 09:37:18
【问题描述】:
编辑:我设法通过使用 virtualenv 使 Twitter 工作。不过,我还是想解决这个问题。
我成功安装并使用了 Tweepy。但是,当我尝试仅使用 Twitter API 时,我收到以下错误
AttributeError: 'module' object has no attribute 'oauth'
我使用的代码来自 Mining the Social Web, 2nd edition:
import twitter
def oauth_login():
# XXX: Go to http://twitter.com/apps/new to create an app and get values
# for these credentials that 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)
return twitter_api
并在以下调用后显示错误:
twitter_api = oauth_login()
print twitter_api
我安装了 oauth,但不知道发生了什么。我需要安装 Tweepy,因为我已经编写了大量可与 Tweepy 一起使用的代码,并且我猜测问题是由于安装了 Tweepy 而引起的。
编辑:书中代码使用https://github.com/sixohsix/twitter
【问题讨论】:
-
请添加使 AttributeError 出现的代码示例。你如何安装 Tweepy?
-
加了代码(当然实际的代码有所有的键)
-
您的问题是您(需要)安装了 python-twitter 和 Tweepy,并且只有安装了两者才会出现错误?只是为了确保我理解您的问题!
-
我做了什么来尝试重现这个:
pip install twitter tweepy(不在 virtualenv 中),然后将源代码写入文件,并添加行oauth_login()(以运行该函数)。但是,它运行没有错误。你可以试试pip install --upgrade twitter tweepy吗?也许你有一个旧版本...