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

aiohttp server reuqest.url broken with yarl >= 1.13 #9435

Closed
1 task done
javajawa opened this issue Oct 8, 2024 · 2 comments
Closed
1 task done

aiohttp server reuqest.url broken with yarl >= 1.13 #9435

javajawa opened this issue Oct 8, 2024 · 2 comments
Labels

Comments

@javajawa
Copy link

javajawa commented Oct 8, 2024

Describe the bug

The changes between yarl 1.12.0 and 1.13.0 have broken the URL parsing in aiohttp when any port is part of the host header. I believe aio-libs/yarl#954 is proximate cause.

The following report primarily refers to a yarl 1.14.0 build, but the reproducer also affected 1.13.0.

To Reproduce

  • Install aiohttp (3.9.5 was used here), and yarl==1.13 or yarl==1.14
  • Run the following code
from aiohttp import web

async def demo(req: web.Request) -> web.Response:
    print(req.url)
    return web.HTTPOk()

app = web.Application()
app.router.add_get('/', demo)
web.run_app(app)
  • Navigate to http://localhost:8080/
  • You will experience an exception.

Expected behaviour

I should be able to access the url property of an incoming request.

Logs/tracebacks

======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
Error handling request
Traceback (most recent call last):
  File "./venv/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./venv/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "./src/test.py", line 5, in demo
    print(req.url)
          ^^^^^^^
  File "aiohttp/_helpers.pyx", line 26, in aiohttp._helpers.reify.__get__
  File "./venv/lib/python3.12/site-packages/aiohttp/web_request.py", line 452, in url
    url = URL.build(scheme=self.scheme, host=self.host)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "./venv/lib/python3.12/site-packages/yarl/_url.py", line 386, in build
    netloc = cls._make_netloc(
             ^^^^^^^^^^^^^^^^^
  File "./venv/lib/python3.12/site-packages/yarl/_url.py", line 1066, in _make_netloc
    ret = cls._encode_host(host) if encode_host else host
          ^^^^^^^^^^^^^^^^^^^^^^
  File "./venv/lib/python3.12/site-packages/yarl/_url.py", line 1049, in _encode_host
    _host_validate(host)
  File "./venv/lib/python3.12/site-packages/yarl/_url.py", line 1616, in _host_validate
    raise ValueError(
ValueError: Host '0.0.0.0:8080' cannot contain ':' (at position 7)

Python Version

$ python --version
Python 3.12.7

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.9.5
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: /usr/local/lib/python3.12/site-packages
Requires: aiosignal, attrs, frozenlist, multidict, yarl
Required-by: ceres

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.1.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /usr/local/lib/python3.12/site-packages
Requires: 
Required-by: aiohttp, yarl

propcache Version

$ python -m pip show propcache
Name: propcache
Version: 0.2.0
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /usr/local/lib/python3.12/site-packages
Requires: 
Required-by: yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.14.0
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /usr/local/lib/python3.12/site-packages
Requires: idna, multidict, propcache
Required-by: aio-pika, aiohttp, aiormq

OS

Linux Debian
Linux [redacted] 5.10.0-24-amd64 #1 SMP Debian 5.10.179-5 (2023-08-08) x86_64 Linux

Related component

Server

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@javajawa javajawa added the bug label Oct 8, 2024
@javajawa javajawa changed the title aiohttp server reuqest.url broken with yarl 1.14 aiohttp server reuqest.url broken with yarl >= 1.13 Oct 8, 2024
@javajawa
Copy link
Author

javajawa commented Oct 8, 2024

This looks like it is a duplicate of #9307, just reading through to work out why I haven't automatically picked up a fix from this closed issue.

@javajawa
Copy link
Author

javajawa commented Oct 8, 2024

Ah, I had an overly tight pin on aiohttp (~= 3.9.5 rather than ~=3.9).
Changing that caused it to rebuild with 3.10.x, which fixed the issue.

Apologies for the noise -- I missed the yarl 1.13 MR on the first pass as I thought it was yarl 1.14, and didn't do my due diligence looking for related issues older than 24 hours.

@javajawa javajawa closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant