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

Documentation misleading on query string encoding #3689

Open
bsolomon1124 opened this issue Apr 11, 2019 · 0 comments
Open

Documentation misleading on query string encoding #3689

bsolomon1124 opened this issue Apr 11, 2019 · 0 comments
Labels
bug documentation Improvements or additions to documentation

Comments

@bsolomon1124
Copy link

bsolomon1124 commented Apr 11, 2019

Long story short

The docs in Passing Parameters in URLs is misleading and the behavior is essentially the opposite of what is stated:

You can also pass str content as param, but beware – content is not encoded by library. Note that + is not encoded.

Expected behaviour

Passing the fully encoded querystring params=url=https%3A%2F%2Fwww.katherinetimes.com.au%2Fstory%2F6005621%2Fwife-of-ex-nissan-boss-ghosn-leaves-japan%2F%3Fsrc%3Drss&api_key=XXXX should not requote the querystring. I'm assuming that's what "content is not encoded by library" is supposed to mean.

What is more accurate is that passing a URL with encoded=True to the url of request() is the only way to get this behavior.

Actual behaviour

From client_reqrep.py:

            q = MultiDict(url.query)
            url2 = url.with_query(params)
            q.extend(url2.query)
            url = url.with_query(q)

Okay, let's try to interpret the above:

>>> import urllib.parse
>>> from yarl import URL
>>> 
>>> base = "https://api.example.com" 
>>> params = {
...     "url": "https://www.katherinetimes.com.au/story/6005621/wife-of-ex-nissan-boss-ghosn-leaves-japan/?src=rss",
...     "api_key": "XXXX",
... }
>>> u = URL(base).with_query(urllib.parse.urlencode(params))
>>> u
URL('https://api.example.com/?url=https://www.katherinetimes.com.au/story/6005621/wife-of-ex-nissan-boss-ghosn-leaves-japan/?src%3Drss&api_key=XXXX')
>>> urllib.parse.urlencode(params)
'url=https%3A%2F%2Fwww.katherinetimes.com.au%2Fstory%2F6005621%2Fwife-of-ex-nissan-boss-ghosn-leaves-japan%2F%3Fsrc%3Drss&api_key=XXXX'

So the query string in u is requoted! (encoded=True always in .with_query().)

What are the docs trying to say here? Am I misinterpreting the phrase "content is not encoded by library"? How so?

Steps to reproduce

See above.

Your environment

aiohttp client 3.5.4, Python 3.7.2, yarl 1.3.0.

@Dreamsorcerer Dreamsorcerer added bug documentation Improvements or additions to documentation labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants