在Django中使用python dropbox API
作者:互联网
我在Django v1.5.3应用程序中使用了针对Dropbox API v1.6所述的DropboxOAuth2Flow方法,当重定向到Dropbox oauth2授权页面时出现400错误.
当我转到我的dropbox_auth_start URL时,我被重定向到:
然后发生400错误.
顺便说一下,“ dropbox-auth-csrf-token”被写入会话文件中.
我的Django代码:
views.py
def get_dropbox_auth_flow(web_app_session):
redirect_uri = "http://www.mydomain.com"
return DropboxOAuth2Flow('blahblahblah', 'blehblehbleh', redirect_uri, web_app_session, "dropbox-auth-csrf-token")
# URL handler for /dropbox-auth-start
def dropbox_auth_start(request):
authorize_url = get_dropbox_auth_flow(request.session).start()
return HttpResponseRedirect(authorize_url)
# URL handler for /dropbox-auth-finish
def dropbox_auth_finish(request):
try:
access_token, user_id, url_state = get_dropbox_auth_flow(request.session).finish(request.GET)
except DropboxOAuth2Flow.BadRequestException, e:
http_status(400)
except DropboxOAuth2Flow.BadStateException, e:
# Start the auth flow again.
return HttpResponseRedirect("http://www.mydomain.com/dropbox_auth_start")
except DropboxOAuth2Flow.CsrfException, e:
return HttpResponseForbidden()
except DropboxOAuth2Flow.NotApprovedException, e:
raise e
except DropboxOAuth2Flow.ProviderException, e:
raise e
urls.py
from django.conf.urls import patterns, url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^dropbox_auth_start/?$',views.dropbox_auth_start),
url(r'^dropbox_auth_finish/?$',views.dropbox_auth_finish),
)
解决方法:
就像@smarx所说的那样,我只是从HTTP和HTTPS切换了,一切正常.
标签:dropbox-api,dropbox,python,django 来源: https://codeday.me/bug/20191030/1967141.html