Andrea Colombo Andrea Colombo - 1 month ago 15
Python Question

Error with tweepy OAuthHandler

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

Answer

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#L26