Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Server Error: /complete/facebook/ -> raise KeyError #153

Closed
Salma7amed opened this issue Jan 12, 2014 · 27 comments
Closed

Internal Server Error: /complete/facebook/ -> raise KeyError #153

Salma7amed opened this issue Jan 12, 2014 · 27 comments

Comments

@Salma7amed
Copy link

I am getting this 500 error mail frequently, stating that on /complete/facebook/ a KeyError is raised. I don't get what is the reason causing it, and how to avoid it.

I am using it on a deployed version so I can't track the scenario that caused so.

@omab
Copy link
Owner

omab commented Jan 12, 2014

Any traceback in the log? Which is the key?

@Salma7amed
Copy link
Author

Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, _callback_args, *_callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
return view_func(_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py", line 32, in wrapper
return func(request, backend, _args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py", line 25, in complete
redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/actions.py", line 54, in do_complete
_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/strategies/base.py", line 69, in complete
return self.backend.auth_complete(_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py", line 71, in auth_complete
'code': self.data['code']

File "/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py", line 23, in getitem
raise KeyError

@omab
Copy link
Owner

omab commented Jan 12, 2014

Do you have the full URL that's triggering that error? The missing code parameter means that something is going wrong in the auth process.

@Salma7amed
Copy link
Author

@omab
Copy link
Owner

omab commented Jan 12, 2014

I've tried to login with Facebook on your site and it worked OK, I was wondering if you have the exact URL that triggered the traceback, like http://order.saludable.me/complete/facebook/?...

@tklovett
Copy link
Contributor

Hitting 'Cancel' Facebook's accept auth request dialog causes a Server Error (500) for @Salma7amed's website

@Salma7amed
Copy link
Author

@omab it seems the problem is as @tklovett stated. How can I avoid the raise of 500 ??!

@omab
Copy link
Owner

omab commented Jan 14, 2014

@Salma7amed, @tklovett, python social auth checks the case of hitting the Cancel button and raises AuthCanceled exception, which can be handled easily with the exceptions middleware at social.apps.django_app.middleware.SocialAuthExceptionMiddleware (add it to the middlewares setting), and also define SOCIAL_AUTH_LOGIN_ERROR_URL or if you prefer SOCIAL_AUTH_FACEBOOK_LOGIN_ERROR_URL. In that page you can show the users a nicer error page, the URL will get a couple of querystring parameters message and backend which are the exception message and the backend name.

@Salma7amed
Copy link
Author

@omab I just discovered that the cancel throws an "AuthCanceled: Authentication process canceled" and not "KeyError" as mentioned in the previous traceback posted.

@omab
Copy link
Owner

omab commented Jan 14, 2014

So, hitting the Cancel button is not the way to reproduce the original report, right?

@Salma7amed
Copy link
Author

Yes it's not.

@omab
Copy link
Owner

omab commented Jan 15, 2014

@Salma7amed, so, which is the full URL that triggers that error?

@Salma7amed
Copy link
Author

According to the traceback I get the following is mentioned:
'REQUEST_URI': '/complete/facebook/?ref=search&fb_source=search',

@omab
Copy link
Owner

omab commented Jan 15, 2014

@Salma7amed, I'm looking for the full URL, I want to see the parameters being sent by Facebook to your site.

@Salma7amed
Copy link
Author

@omab How can I get you this info. Especially that I have no idea when this error is triggered. I just get the 500 error email from django.

@omab
Copy link
Owner

omab commented Jan 15, 2014

@Salma7amed, could you forward me that email or does it have any sensible data? What about your server logs? At some point the traceback should appear there with a full URL above that triggered the bug.

@Salma7amed
Copy link
Author

@omab to which mail shall I send the mail ??!.

@omab
Copy link
Owner

omab commented Jan 15, 2014

@omab
Copy link
Owner

omab commented Jan 15, 2014

@Salma7amed, I've checked your email, where's ?ref=search&fb_source=search appended to the complete URL? It's something from your code? Or something defined in the Facebook app? There's any chance these clients request come from some indexed data or bots hitting your service?

@Salma7amed
Copy link
Author

@omab I think if it was in the facebook app or in my code, it would have been appearing for all users who try to signup with facebook ??

@omab
Copy link
Owner

omab commented Jan 15, 2014

@Salma7amed, any chance that this is being caused by a mobile client? So far I see the wrong parameters being sent to /complete/facebook/, how is that happening I don't know, could be a bug on Facebook or the URL is being triggered by hand.

I've added a change to catch the missing parameter and raise a social exception that can be processed with the middleware.

@Salma7amed
Copy link
Author

Where can I find the change u've added ??. And how will it help in finding what is causing this problem ??.

@omab
Copy link
Owner

omab commented Jan 16, 2014

@Salma7amed, I've just released v0.1.19 which carries the fix. This won't help on finding the root of the issue but will give you control over the 500 error. So far my understanding of the problem is that at some point something is following the URL /complete/facebook/, the extra parameters look suspicious to me. I would recommend to check the server log and check the auth process before that error, also check the referrer for the one that triggers the error.

@Salma7amed
Copy link
Author

ok, now after upgrading to the latest version. The following is the error I get:

Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, _callback_args, *_callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
return view_func(_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py", line 45, in wrapper
return func(request, backend, _args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py", line 21, in complete
redirect_name=REDIRECT_FIELD_NAME, _args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/actions.py", line 44, in do_complete
_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/strategies/base.py", line 67, in complete
return self.backend.auth_complete(_args, *_kwargs)

File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py", line 56, in auth_complete
raise AuthMissingParameter(self, 'code')

AuthMissingParameter: Missing needed parameter code

@omab
Copy link
Owner

omab commented Jan 19, 2014

Yes, that's expected since there are missing parameters to continue the process. As mentioned in my previous comment, I would check the server log and check the auth process before that error, also check the referrer for the request that triggers the error.

@omab
Copy link
Owner

omab commented Feb 10, 2014

@Salma7amed, any progress on your end? Can I close this issue?

@omab
Copy link
Owner

omab commented Feb 12, 2014

Closing by inactivity.

@omab omab closed this as completed Feb 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants