Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix 'WSGIRequest' object does not support item assignment error#152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
iamlordaubrey wants to merge1 commit intodropbox:master
base:master
Choose a base branch
Loading
fromiamlordaubrey:fix_oauth_type_error

Conversation

iamlordaubrey
Copy link

@iamlordaubreyiamlordaubrey commentedJul 22, 2018
edited
Loading

  • Delete request arguments in functions. It is redundant as the first argument is usually the request object
  • Reference the session object on the request (web_app_session.session). This fixesself.session[self.csrf_token_session_key] = csrf_token error

- Delete request arguments in functions. It is redundant as the first argument is usually the request object- Call the session method on the request object (web_app_session.session). This fixes `self.session[self.csrf_token_session_key] = csrf_token` error
@greg-db
Copy link
Contributor

Thanks!

@iamlordaubrey
Copy link
Author

@starforever might I also suggest changingweb_app_session torequest, as they are basically the same thing and the namerequest is more intuitive.

Copy link
Contributor

@starforeverstarforever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the error happens when you pass in an object forweb_app_session which should actually be adict.

I think we should keep these parameters simple, rather than making them some objects with fields likesession orquery_params without explicitly specifying how they are constructed. This makes it easier for others to understand the example code regardless of what libraries they use for building requests.

try:
oauth_result = \\
get_dropbox_auth_flow(web_app_session).finish(
get_dropbox_auth_flow(web_app_session.session).finish(
request.query_params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If you removerequest you need to find proper replacement for all its usages within the function. Otherwise the code will break.

@iamlordaubrey
Copy link
Author

Ok, I think I understand.

DropboxOAuth2Flow class needs to take in web_app_session. However, the documentation would be wrong for Django's implementation because the URL handlers for/dropbox-auth-start and/dropbox-auth-finish (that is, the functionsdropbox_auth_start anddropbox_auth_finish) take inrequest as the first (and in function-based views, the only) argument.

It is that request's session (request.session) that needs to be passed to DropboxOAuth2Flow __init__ method.

My point is,web_app_session needs to be passed to DropboxOAuthFlow class, but in Django, thatweb_app_session is found in therequest object asrequest.session. Also,request is the first parameter the URL handler takes in;

Therefore for Django:

defget_dropbox_auth_flow(web_app_session):redirect_uri="https://my-web-server.org/dropbox-auth-finish"returnDropboxOAuth2Flow(APP_KEY,APP_SECRET,redirect_uri,web_app_session,"dropbox-auth-csrf-token")# URL handler for /dropbox-auth-startdefdropbox_auth_start(request):authorize_url=get_dropbox_auth_flow(request.session).start()redirect_to(authorize_url)# URL handler for /dropbox-auth-finishdefdropbox_auth_finish(request):try:oauth_result= \get_dropbox_auth_flow(request.session).finish(request.query_params)exceptBadRequestException,e:http_status(400)    ...

For Flask, session is global. We would just need to access it directly:

fromflaskimportsession,requestdefget_dropbox_auth_flow(web_app_session):redirect_uri="https://my-web-server.org/dropbox-auth-finish"returnDropboxOAuth2Flow(APP_KEY,APP_SECRET,redirect_uri,web_app_session,"dropbox-auth-csrf-token")# URL handler for /dropbox-auth-start@app.route('/dropbox-auth-start')defdropbox_auth_start():authorize_url=get_dropbox_auth_flow(session).start()redirect_to(authorize_url)# URL handler for /dropbox-auth-finish@app.route('/dropbox-auth-finish')defdropbox_auth_finish():try:oauth_result= \get_dropbox_auth_flow(session).finish(request.query_params)exceptBadRequestException,e:http_status(400)    ...

The documentation specified two arguments,web_app_session andrequest, and that's what tripped me originally. With django, only one is needed which is request. With Flask, none is needed.

I think with Django's implementation, implementing for Flask would be clear and straightforward to a newbie.

@rogebrdrogebrd self-requested a reviewMarch 30, 2020 17:29
@rogebrd
Copy link
Contributor

Hello, is this something you are still interested in working on?

@iamlordaubrey
Copy link
Author

Hello, is this something you are still interested in working on?

Sure@rogebrd. I'll take a look at the failing test

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign ourContributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let usrecheck it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@starforeverstarforeverstarforever left review comments

@rogebrdrogebrdAwaiting requested review from rogebrd

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@iamlordaubrey@greg-db@rogebrd@CLAassistant@starforever

[8]ページ先頭

©2009-2025 Movatter.jp