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

URL encoding error #124

Closed
FransKnibbe opened this issue May 20, 2014 · 6 comments
Closed

URL encoding error #124

FransKnibbe opened this issue May 20, 2014 · 6 comments

Comments

@FransKnibbe
Copy link

I tried OAuth 1 based on the OAuth workflow example at http:https://requests-oauthlib.readthedocs.org/en/latest/oauth1_workflow.html, but I get an error:

[snip]
File "C:\Python34\lib\site-packages\oauthlib-0.6.1-py3.4.egg\oauthlib\common.p
y", line 135, in urldecode
ValueError: Not a valid urlencoded string.

By the way, the same issue was raised on stackoverflow:
http:https://stackoverflow.com/questions/22965459/oauth1-with-requests-oauthlib-produces-url-encoding-error

@Lukasa
Copy link
Member

Lukasa commented May 20, 2014

This error comes from urldecoding the response body, because Twitter is erroring out. Are you actually using 'a' and 'b' as your client key and secret? If you are, that will cause Twitter to refuse to validate you. If you aren't, you should confirm you've set them correctly.

@FransKnibbe
Copy link
Author

In my test I was not contacting Twitter, but another (less well known) service. I did not use 'a' and 'b' in my attempt, but the consumer key and signature that were provided to me by the OAuth provider.

Anyway, it is good to know what probably caused the error. Is there a (recommended) way to catch and handle errors that may occur when calling oauth.fetch_request_token()?

@Lukasa
Copy link
Member

Lukasa commented May 20, 2014

Not as far as I know: it might be nice to wrap this more cleanly for debugging and error handling purposes. @ib-lundgren, thoughts?

@ib-lundgren
Copy link
Member

First off, my apologies for this horribly vague error message. The error message is an old sore issue but will finally be updated the coming week since I now have time to work on OSS again.

Regarding how to handle it I think the best way forward is to update fetch_request_token to deal with either a denied request or an incorrectly formatted responses better. Probably by raising something like

  • TokenRequestDenied, for 401
  • TokenRequestInvalid, for 400

with a much better error message for both.

Stay tuned for a fix the coming week.

@ib-lundgren
Copy link
Member

Decided to stick to ValueError for now but at least the error message should be much clearer and I've added a check for status codes over 400 to help out a bit there too.

Added a bit more logging to so in the future, when you run into things, adding

import logging
import sys
log = logging.getLogger('requests_oauthlib')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.DEBUG)

# And if you really want detail.
log = logging.getLogger('oauthlib')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.DEBUG)

might shed some light as well.

@ib-lundgren
Copy link
Member

Hrm, while most of these errors will likely be during development there might be some benefit to differentiating the 40x responses from the decoding error. Will add a TokenRequestDenied error with a status_code attribute for you to use.

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