Forum Discussion

abhannan's avatar
abhannan
Helpful | Level 5
8 years ago

Python DropboxOAuth2Flow Error: WSGIRequest' object does not support item assignment

I'm trying to build a webapp with Django and using dropbox SDK v2 for Python. I'm stuck at Authentication and getting error that 

WSGIRequest' object does not support item assignment

 

Here is my code:

 

 

from dropbox import DropboxOAuth2Flow
from django.shortcuts import redirect

def get_dropbox_auth_flow(web_app_session):
    redirect_uri = "https://www.my-dummy-server.com"
    APP_KEY = 'my-app-key'
    APP_SECRET = 'my-app-secret'
    return DropboxOAuth2Flow(
        APP_KEY, APP_SECRET, redirect_uri, web_app_session, "dropbox-auth-csrf-token")

def dropbox_auth_start(web_app_session):
    authorize_url = get_dropbox_auth_flow(web_app_session).start()
    return redirect(authorize_url)

 Can anyone please help?

  • abhannan's avatar
    abhannan
    Helpful | Level 5

    I changed the code to the following but still I'm not able to resolve.

     

    def dropbox_auth_start(request, web_app_session):
    if request.method == 'GET':
    authorize_url = get_dropbox_auth_flow(web_app_session).start()
    return redirect(authorize_url)

    I'm learning dropbox API, isn't there any example / gist / tutorial that how OAuth authentication works in API. I'm not able to find anything on the internet.

  • iamlordaubrey's avatar
    iamlordaubrey
    Explorer | Level 3

    In case someone needs this:

    The first argument passed is usually the request object. Simply reference the session object on the request like so: web_app_session.session

     

    Updated:

    from dropbox import DropboxOAuth2Flow
    from django.shortcuts import redirect
    
    def get_dropbox_auth_flow(web_app_session):
        redirect_uri = "https://www.my-dummy-server.com"
        APP_KEY = 'my-app-key'
        APP_SECRET = 'my-app-secret'
        return DropboxOAuth2Flow(
            APP_KEY, APP_SECRET, redirect_uri, web_app_session, "dropbox-auth-csrf-token")
    
    def dropbox_auth_start(web_app_session):
        authorize_url = get_dropbox_auth_flow(web_app_session.session).start()
        return redirect(authorize_url)