-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ValueError when redirecting to URL with incorrect schema #3315
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #3149 (Raise "TooManyRedirects" when redirect to new url with different host), #499 (Url GET parameters are lost when redirecting), #824 (URL with #), #1996 ([Client] Incorrect handling of '..' in url path.), and #56 (Redirect loop). |
@berislavlopac I'd like to emphasize that it is not an invalid/incorrect schema, it's just non-HTTP. I however agree with you that there must be a better exception retaining all context information needed. |
Yes, that was basically my comment that we need something more informative and easier to manage upstream than |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
This patch introduces 5 granular user-facing exceptions that may occur when HTTP requests are made: * `InvalidUrlClientError` * `RedirectClientError` * `NonHttpUrlClientError` * `InvalidUrlRedirectClientError` * `NonHttpUrlRedirectClientError` Previously `ValueError` or `InvalidURL` was raised and screening out was complicated (a valid URL that redirects to invalid one raised the same error as an invalid URL). Ref: #6722 (comment) PR #6722 Resolves #2507 Resolves #2630 Resolves #3315 Co-authored-by: Sviatoslav Sydorenko <[email protected]>
This patch introduces 5 granular user-facing exceptions that may occur when HTTP requests are made: * `InvalidUrlClientError` * `RedirectClientError` * `NonHttpUrlClientError` * `InvalidUrlRedirectClientError` * `NonHttpUrlRedirectClientError` Previously `ValueError` or `InvalidURL` was raised and screening out was complicated (a valid URL that redirects to invalid one raised the same error as an invalid URL). Ref: aio-libs#6722 (comment) PR aio-libs#6722 Resolves aio-libs#2507 Resolves aio-libs#2630 Resolves aio-libs#3315 Co-authored-by: Sviatoslav Sydorenko <[email protected]> (cherry picked from commit fb465e1)
…rchy in the HTTP client (#8158) **This is a backport of PR #6722 as merged into master (fb465e1).** This patch introduces 5 granular user-facing exceptions that may occur when HTTP requests are made: * `InvalidUrlClientError` * `RedirectClientError` * `NonHttpUrlClientError` * `InvalidUrlRedirectClientError` * `NonHttpUrlRedirectClientError` Previously `ValueError` or `InvalidURL` was raised and screening out was complicated (a valid URL that redirects to invalid one raised the same error as an invalid URL). Ref: #6722 (comment) PR #6722 Resolves #2507 Resolves #2630 Resolves #3315 Co-authored-by: Sviatoslav Sydorenko <[email protected]> (cherry picked from commit fb465e1)
Long story short
When the Client handles redirection, if the redirected URL contains an incorrect schema, it throws a
ValueError
:aiohttp/aiohttp/client.py
Line 453 in ced1058
While this is technically correct, it is more sensible to expect some kind of more specific error.
Expected behaviour
I would expect the Client to throw an
aiohttp
-specific error, preferablyInvalidURL
.Actual behaviour
The Client throws a generic
ValueError
, which is difficult to specifically handle.Steps to reproduce
Create a redirection URL, e.g. using an URL shortener like https://tinyurl.com/, and have it redirect to any URL with an incorrect schema, for example
file://foo/bar
. Then, call it withaiohttp
Output:
Your environment
Python 3.6.6, and the installed packages:
The text was updated successfully, but these errors were encountered: