-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Request url of client session gets malformed #3424
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #660 (aiohttp.request hangs on some URLs), #1686 (Client Session Timeouts - Usage Question), #3203 (session.get(...) timeout overriding ClientSession timeout and cancelling all requests), #388 (request.GET ignores blank values), and #2039 (Graceful shutdown for client sessions). |
URL processing is performed by yarl library: https://yarl.readthedocs.io/en/latest/
Roughly, path contains strings or pchar segments delimited by slashes. Both
Thus, the conversion is legal. Hope it helps. |
Thank you for your swift yet full answer! Sorry i didn't find it on my own and wasted your time :) |
@asvetlov I urge you to reopen this issue and nix the In my case, rewriting the URL broke my OAuth requests. I calculated an OAuth signature header from the URL, and then I passed the URL and signature header to aiohttp. aiohttp silently rewrote the URL, invalidating the signature, making the server respond with an Access Denied message. Please be patient while I rant for one paragraph. Simply put, this is unbecoming of an HTTP library. I found this issue after spending a day today fiddling with OAuth libraries: it never crossed my mind to read this doc. I've used dozens of HTTP libraries in dozens of programming languages, and never have I even heard of automatic URL rewrites. Especially not when my URL is valid to begin with. Rewriting URLs is akin to an IRC client auto-correcting typos, or a CSV encoder trimming whitespace: just, no. I realize changing this default would require a major version change. I think it's worth it. Python needs a low-level async HTTP library, far more than it needs ... uh ... a library that rewrites URLs and does async HTTP requests. |
[finishes #162176560]. The problem was _not_ on Twitter's end: it's a bug in our HTTP library. This is infuriating. The upstream bug is aio-libs/aiohttp#3424 and it is marked "invalid". We use aiohttp in a few places; I think I covered them all. This should resolve similar issues we may face in the future.
I feel your pain, but things like request signature need a slightly different feature: request preparing as a separate execution step. Now you call |
Thanks for the response. That leads me to two separate questions.
|
Man, aiohttp has no relation to aiohttp is a Free Open Source Software, distributed under Apache License:
Basically you pay nothing but get no guarantees (including a support guarantee) back. You have choices:
The decision is up to you, but I would mention that your current attitude doesn't help to convince. |
I understand the whole "no guarantees" thing. I am trying to be constructive here. A fork can be totally amicable. I felt jarred when I found that aiohttp rewrote my URL, because I had jumped to the conclusion that aiohttp is "urllib3, async." That was my mistake as a user. I had assumed aiohttp is like urllib3 but async, simply because I assumed "urllib3 but async" would exist somewhere, and since aiohttp is popular I assumed that was it. That's why I'm asking about aiohttp's intent: is aiohttp is meant to fill that gap, or is aiohttp something else? (If aiohttp is something else, then forking would mean everybody wins, in the same way that http and urllib3 and requests are symbiotic.) Or maybe I'm leaping over swaths of conversation here with my assumptions.... The aiohttp fix I propose is: when given a Does that fix sound compelling? |
Let's return to the root. aiohttp does requote URLs by default. Requoting is more questionable. Should
Should
Essentially a path is a sequence of pchar delimited by That's why I hope this text will help you to understand aiohttp design decision better and can be the backgound for discussion. |
As I understand it, the reason for quoting is: if the user makes a mistake, aiohttp should fix it. Is that the intent? |
Kind of. |
I totally understand the rationale for correcting users' mistakes in a similar vein to how My view: yes, sometimes it's nice to correct users' mistakes silently; but I also want a library that doesn't correct mistakes silently. I doubt I'm alone in that desire. In Python, I want
So for me, there are two issues:
(And yes, of course |
Long story short
When using ClientSession to make HTTP-request and request url gets parsed in client session (here), some percent-encoded strings get un-encoded before executing request.
Expected behaviour
Valid urls should not be changed.
Actual behaviour
Urls that contain percent-encoded params that are considered "safe" are un-encoded before request. This makes some cases where url is processed incorrectly. For example, im currently working with an internal api that has endpoint like
GET ../abc/def/{resource_id}
, whereresource_id
can be any string. The problem is that while it expects some encoded string, the only thing i can manage with aiohttp is malformed id, because percent-encoded strings get partially un-encoded.For example
url
value before and after this code line:I'm not 100% sure that the problem i got is located there, but that makes sense to me, as second line does not resolve in browser while first one resolves just fine.
Steps to reproduce
Issue can be somewhat reproduced with following script. Note that httpbin is a bad example in that case because it will percent-decode in its JSON response.
Your environment
OS: ubuntu 17.04
Python: 3.6.6
aiohttp: 2.3.10 or 3.4.4 (can be reproduced on both)
The text was updated successfully, but these errors were encountered: