1

I'm trying to learn Dropbox API and want to use OAuth 2 for authorization. I'm getting following error:

dropbox_auth_start() missing 1 required positional argument: 'request'

Here is my code:

Views.py

from dropbox import DropboxOAuth2Flow
from django.shortcuts import redirect

def get_dropbox_auth_flow(web_app_session):
    redirect_uri = "https://www.my-dummy-url.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, request):
    if request.method == 'GET':
        authorize_url = get_dropbox_auth_flow(web_app_session).start()
        return redirect(authorize_url)

urls.py

urlpatterns = [
    path('dropbox/', views.dropbox_auth_start, name='dropbox')
]
1

2 Answers 2

2

An aside... as @at14 said, request object needs to be the first argument. The first argument is the request object (in this case, web_app_session is the request object). The second argument called 'request' (in the dropbox_auth_start function) is not needed.

More to the point, session object needs to be called on the request object like so: web_app_session.session

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

Essentially, web_app_session == request, so adding the if block, you'd get:

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

Of course, web_app_session can be switched with request.

1

request object needs to be the first argument to your function

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)
2
  • Thanks, I did and now its complaining that: dropbox_auth_start() missing 1 required positional argument: 'web_app_session'
    – Hannan
    Commented Jan 28, 2018 at 15:21
  • Yep, what's web_app_session ? Who is going to pass it? If you add it as an argument in a view it needs to be passed through the URL
    – at14
    Commented Jan 28, 2018 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.