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

KeyError occurs when redirect to custom scheme(ex. market://) #822

Closed
holyachon opened this issue Feb 24, 2020 · 3 comments · Fixed by #1002
Closed

KeyError occurs when redirect to custom scheme(ex. market://) #822

holyachon opened this issue Feb 24, 2020 · 3 comments · Fixed by #1002
Labels
user-experience Ensuring that users have a good experience using the library

Comments

@holyachon
Copy link

Information

OS platform : mac OS
Python version : 3.7.2
Installed dependencies and versions : httpx==0.9.3
Code snippet

    @property
    def port(self) -> int:
        port = self._uri_reference.port
        if port is None:
            return {"https": 443, "http": 80}[self.scheme]
        return int(port)

Error traceback

[2020-02-24 14:57:08 +0900] [82150] [ERROR] Exception
Traceback (most recent call last):
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/sanic/testing.py", line 120, in _collect_response
    method, url, *request_args, **request_kwargs
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/sanic/testing.py", line 41, in _local_request
    url, verify=False, *args, **kwargs
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 671, in get
    trust_env=trust_env,
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 268, in request
    trust_env=trust_env,
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 410, in send
    allow_redirects=allow_redirects,
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 478, in send_handling_redirects
    request = self.build_redirect_request(request, response)
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 500, in build_redirect_request
    headers = self.redirect_headers(request, url, method)
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/client.py", line 555, in redirect_headers
    if url.origin != request.url.origin:
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/models.py", line 215, in origin
    return Origin(self)
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/models.py", line 287, in __init__
    self.port = url.port
  File "/Users/sym/.pyenv/versions/airbridge-ads-was/lib/python3.7/site-packages/httpx/models.py", line 165, in port
    return {"https": 443, "http": 80}[self.scheme]
KeyError: 'market'
[2020-02-24 14:57:08 +0900] [82150] [INFO] Starting worker [82150]
[2020-02-24 14:57:08 +0900] [82150] [INFO] Stopping worker [82150]
[2020-02-24 14:57:08 +0900] [82150] [INFO] Server Stopped

Description

i'm using sanic and sanic uses httpx to test web request.
when i make a redirect response which goes to "market://details?id=~~" (android market url)", KeyError occurred.
I think it is associated with port property method.
Is this the intended behavior?

Thank you.

@florimondmanca
Copy link
Member

Hi @holyachon, I believe this was fixed in a recent release — can’t dig up the issue right now but I remember we now use defaults for the port instead of direct key access.

Can you upgrade to the latest version and confirm this is now resolved?

@holyachon
Copy link
Author

holyachon commented Feb 24, 2020

hi @florimondmanca , thank you for your quick reply :)
I tested same case with httpx==0.11.1, but same error occurs.

i made a redirect response which goes to "market://test", and error trace is below.

  File "/Users/sym/.pyenv/versions/workbox/lib/python3.7/site-packages/httpx/models.py", line 148, in port
    return {"https": 443, "http": 80}[self.scheme]
KeyError: 'market'

@tomchristie
Copy link
Member

Okay, so this ought to error by default since "market" isn't a valid HTTP scheme, but it could do so more gracefully, and we ought to allow it to be supported by explicitly mounting a dispatcher class for market. (Eg. mentioned in passing at #769 (comment))

For example curl will fail with curl: (1) Protocol "market" not supported or disabled in libcurl, and requests will fail with requests.exceptions.InvalidSchema: No connection adapters were found for 'market://details?id=~~'

@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Feb 25, 2020
jcugat added a commit to jcugat/httpx that referenced this issue May 27, 2020
jcugat added a commit to jcugat/httpx that referenced this issue May 27, 2020
jcugat added a commit to jcugat/httpx that referenced this issue May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants