1
编辑:我设法通过使用virtualenv使Twitter工作。不过,我仍然想解决这个问题。Tweepy和Twitter不能一起工作
我成功安装并使用了Tweepy。然而,当我尝试只使用Twitter的API,我收到以下错误
AttributeError: 'module' object has no attribute 'oauth'
我使用的代码是从挖掘社交网络,第2版:
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
,并显示错误下面的调用之后:
我已经安装的OAuth,我无法弄清楚到底是怎么回事。我需要安装Tweepy,因为我已经编写了一大段与Tweepy一起工作的代码,我猜测这个问题是由于安装了Tweepy而引起的。
编辑:书中的代码使用https://github.com/sixohsix/twitter
请添加代码示例,使AttributeError的出现。你如何安装Tweepy? –
添加了代码(当然,实际代码中包含所有的键) – Anastasia
您的问题(您需要)安装了python-twitter和Tweepy,并且只有在安装时才会出现错误?只是为了确保我明白你的问题! –