Error with tweepy OAuthHandler

我是研究僧i 提交于 2019-12-07 09:57:56

问题


I'm new here and kind of unexperienced with python, so sorry if the question is trivial.

I have this simple script, to fetch followers of a given twitter user:

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)

of course xxx,yyy,etc are being set in my script with API key, secret, access token etc

I get this error:

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'

Is anyone able to help me? Can't understand what am I doing wrong.

Thanks Andrea


回答1:


The tweepy module object has no attribute 'OAuthHandler',You should import like this,

from tweepy.auth import OAuthHandler

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

Reference here https://github.com/tweepy/tweepy/blob/master/tweepy/auth.py#L29



来源:https://stackoverflow.com/questions/26075001/error-with-tweepy-oauthhandler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!