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

We should try to convert the variable first but not to raise an unnecessary exception. #816

Closed
wants to merge 1 commit into from

Conversation

ayanamist
Copy link
Contributor

Since i pass the dict object with str and int object, an exception will be raised.

Exception on /post [POST]
Traceback (most recent call last):
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/Flask-0.9-py2.7.zip/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/Flask-0.9-py2.7.zip/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/Flask-0.9-py2.7.zip/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/Flask-0.9-py2.7.zip/flask/app.py", line 1344, in dispatch_request
return self.view_functionsrule.endpoint
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/application/utils/decorators.py", line 10, in decorated_view
return func(_args, *_kwargs)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/application/views/status.py", line 19, in status_post
result = flask.g.api.reTweet(id=retweet_id, include_entities=1)
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/twython-2.3.3.zip/twython/twython.py", line 138, in
return lambda *_kwargs: self._constructFunc(key, *_kwargs)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/twython-2.3.3.zip/twython/twython.py", line 155, in _constructFunc
content = self._request(url, method=fn['method'], params=kwargs)
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/twython-2.3.3.zip/twython/twython.py", line 175, in _request
response = func(url, data=params, files=files)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/sessions.py", line 295, in post
return self.request('post', url, data=data, **kwargs)
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/sessions.py", line 252, in request
r.send(prefetch=prefetch)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/models.py", line 532, in send
r = self.auth(self)
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/auth.py", line 103, in call
unicode(r.full_url), unicode(r.method), r.data, r.headers)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/packages/oauthlib/oauth1/rfc5849/init.py", line 211, in sign
request.oauth_params.append((u'oauth_signature', self.get_oauth_signature(request)))
File "/base/data/home/apps/sdabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/packages/oauthlib/oauth1/rfc5849/init.py", line 71, in get_oauth_signature
normalized_params = signature.normalize_parameters(collected_params)
File "/base/data/home/apps/s
dabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/packages/oauthlib/oauth1/rfc5849/signature.py", line 373, in normalize_parameters
key_values = [(utils.escape(k), utils.escape(v)) for k, v in params]
File "/base/data/home/apps/s~dabr-gae/1.361315839962791826/lib/requests-0.13.9.zip/requests/packages/oauthlib/oauth1/rfc5849/utils.py", line 52, in escape
raise ValueError('Only unicode objects are escapable.')
ValueError: Only unicode objects are escapable.

The related code is here: https://code.google.com/p/gabr/source/browse/application/views/status.py?r=c67d65b90bdf78d07d4fe92cc1e8f9827cb5eaf8#22

So i must unicode the parameters first: https://code.google.com/p/gabr/source/browse/application/views/status.py?r=7eb65d488db14fb1ced0c848c0334f894191ab7b#20

It's caused by https://github.com/kennethreitz/requests/blob/9576518d69b819b25cd036397d2624daa6ae088c/requests/packages/oauthlib/oauth1/rfc5849/utils.py#L52 which will check the type of the parameters.

But i think it's not necessary, because what common.quote do is that it encode the unicode string to utf8, call urllib.quote and decode it. I think even this unicode intermediate object is unnecessary, because the only calling is from https://github.com/kennethreitz/requests/blob/9576518d69b819b25cd036397d2624daa6ae088c/requests/packages/oauthlib/oauth1/rfc5849/signature.py#L373 which convert the object to unicode string again in the next statement.

And i think common.quote is unncessary, because the only calling is from oauth1/rfc5849/utils.py , the rest in this package is directly calling urllib.quote.

So i think, we should just encoding it if it's a unicode object or do nothing else.

@travisbot
Copy link

This pull request passes (merged c4ad0fa into b9ecf45).

@kennethreitz
Copy link
Contributor

This issue should be opened against oauthlib, not requests.

https://github.com/idan/oauthlib

@rbpasker
Copy link

rbpasker commented Feb 1, 2013

I'm, also getting "ValueError: Only unicode objects are unescapable" with latest quote patch

here are two lines of code that provoke the error:

request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken?oauth_consumer_key'
r = requests.post(url=request_token_url, auth=oauth)

if i change the URL to not have a query parameter, then the error is not raised (but the endpoint is wrong'):

request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken'
r = requests.post(url=request_token_url, auth=oauth)

making it a unicode string (u'xxxx') doesn't help.
adding

from __future__ import unicode_literals

doesn't help

i'm really stuck here, if someone could provide a suggestion. thanks

File "/Users/rbp/Projects/tengahdb/lib/python2.7/site-packages/oauthlib/oauth1/rfc5849/utils.py", line 64, in unescape
raise ValueError('Only unicode objects are unescapable.')
ValueError: Only unicode objects are unescapable.

@rbpasker
Copy link

rbpasker commented Feb 1, 2013

ok, here's how i got around the problem:

request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken'
payload={'oauth_consumer_key':""}
r = requests.post(url=request_token_url, auth=oauth, params=payload)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants