ImportError: cannot import name 'OAuth1Session' from 'requests_oauthlib'

1.3k Views Asked by At

I am new to django framework. I tried to create a login authentication through twitter using tweepy. While saving the fetched data in my db, I am facing this issue for OAuth1Session. I have tweepy installed. I have also installed requests_oauthlib, but still doesn't able to resolve this error.

from tweepy.auth import OAuthHandler  #error called here (**ImportError: cannot import name 'OAuth1Session' from 'requests_oauthlib'** )
from .models import Tweet
import credentials

def user_tweets():
    auth = OAuthHandler(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET)
    auth.set_access_token(credentials.ACCESS_TOKEN, credentials.ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth)
    user_tweets = api.user_timeline(count=50)
    return user_tweets
1

There are 1 best solutions below

1
On

Make sure you've installed requests as well. So, for example, you can do this:

$ pip install requests requests_oauthlib

or

$ pip3 install requests requests_oauthlib