使用tweepy OAuthHandler时出错

时间:2014-09-27 13:09:31

标签: python tweepy

我是新来的,对python缺乏经验,如果这个问题很简单,那就很抱歉。

我有这个简单的脚本,用于获取给定Twitter用户的关注者:

import time
import tweepy

consumer_key="xxx"
consumer_secret="yyy"
access_token="zzz"
access_token_secret="www"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

当然xxx,yyy等在我的脚本中设置了API密钥,密钥,访问令牌等

我收到此错误:

c:\Development>c:\Python27\python.exe get_followers.py
Traceback (most recent call last):
File "get_followers.py", line 4, in 
auth = tweepy.OAuthHandler('xxx', 'yyy')
AttributeError: 'module' object has no attribute 'OAuthHandler'

有人能帮助我吗? 无法理解我做错了什么。

由于 安德烈

1 个答案:

答案 0 :(得分:6)

tweepy module对象没有属性' OAuthHandler',您应该像这样导入,

from tweepy.auth import OAuthHandler

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

此处参考https://github.com/tweepy/tweepy/blob/master/tweepy/auth.py#L29