ImportError:无法从“ requests_oauthlib”导入名称“ OAuth1Session”

问题描述

我是django框架的新手。我尝试使用tweepy通过Twitter创建登录身份验证。在将获取的数据保存到数据库中的同时,我遇到了OAuth1Session的问题。我安装了tweepy。我还安装了requests_oauthlib,但仍然无法解决此错误。

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

解决方法

确保还安装了requests。因此,例如,您可以执行以下操作:

$ pip install requests requests_oauthlib

$ pip3 install requests requests_oauthlib

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...