Error importing Tweepy with Python

Viewed 2591

I've installed tweepy and have no problem with "import tweepy" being in my code. When I try to use anything in tweepy, however, I'm faced with the following error: "ImportError: cannot import name 'OAuthHandler'"

    from tweepy import OAuthHandler
    consumer_token = 'XXX'
    consumer_secret = 'YYY'
    auth = tweepy.OAuthHandler(consumer_token, consumer_secret)

All solutions on stackoverflow say to try this, but it still does not work for me

    from tweepy.auth import OAuthHandler
    consumer_token = 'XXX'
    consumer_secret = 'YYY'
    auth = tweepy.OAuthHandler(consumer_token, consumer_secret)
4 Answers

I do not know why it works, but it did for me. first import tweepy and then separately OAuthHandler. use both lines:

import tweepy
from tweepy import OAuthHandler

and change other lines to:

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