gpt4 book ai didi

python - 错误:global name 'oauth_token' is not defined

转载 作者:太空宇宙 更新时间:2023-11-03 19:03:03 26 4
gpt4 key购买 nike

我正在 Django 中使用 django-social-authtweepy 使用其 api 将推文发布到 Twitter。使用 Twitter 登录工作正常,但在发布推文时,我从views.py 收到此错误:未定义全局名称“oauth_token”。提前致谢。

from django.shortcuts import render
from django.contrib.auth import logout
from social_auth.models import UserSocialAuth
import tweepy
from twapp import settings


def index(request):
if request.method == 'POST':

instance = UserSocialAuth.objects.filter(user=request.user).get()
oauth_access_token = (instance.tokens).get(oauth_token)

oauth_access_secret = (instance.tokens).get(oauth_token_secret)
print oauth_access_token
auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
auth.set_access_token(oauth_access_token, 'oauth_access_secret')
api = tweepy.API(auth)
print api.me().name
api.update_status('Updating using OAuth authentication via Tweepy!')
return render(request, 'home.html')


def logout_view(request):
logout(request)
return render(request, 'home.html')

最佳答案

忘记双引号

oauth_access_token = (instance.tokens).get('oauth_token')

关于python - 错误:global name 'oauth_token' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com