microsoft / botbuilder-python

The Microsoft Bot Framework provides what you need to build and connect intelligent bots that interact naturally wherever your users are talking, from text/sms to Skype, Slack, Office 365 mail and other popular services.
http://botframework.com
MIT License
715 stars 286 forks source link

aiohttp version (<3.10.7) issue with host header having port specified or IPv6 IP #2192

Open babs opened 3 days ago

babs commented 3 days ago

Version

botbuilder-integration-aiohttp 4.16.2

Describe the bug

botbuilder-integration-aiohttp-4.16.2 is dependant of aiohttp-3.10.5 but aiohttp-3.10.5 suffers an issue that seems to be fixed in aiohttp-3.10.7.

Issue is you can't use the Request.url property if the host header contains port or is IPv6 IP.

To Reproduce

Steps to reproduce the behavior:

  1. create a basic example of bot (or see bellow for a smaller reproducible issue)
  2. in the handler, just print or use request.url
  3. witness the 500 response

Expected behavior

I'd expect the request to not fail and get the object as expected

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

full repro case

mkdir /tmp/aiohttp-issue
cd /tmp/aiohttp-issue
python3 -m venv .venv
. .venv/bin/activate
pip install aiohttp==3.10.5 # version botbuilder-integration-aiohttp-4.16.2 is using

cat > example.py <<EOF
from aiohttp import web

async def hello(request):
    return web.Response(text=f"Hello, world: {request.url.path}")

app = web.Application()
app.add_routes([web.get('/', hello)])

web.run_app(app)
EOF

python3 example.py

output when curl localhost:8080 from another terminal:

======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)
Error handling request
Traceback (most recent call last):
  File "/tmp/aiohttp-issue/.venv/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/aiohttp-issue/.venv/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/aiohttp-issue/example.py", line 4, in hello
    return web.Response(text=f"Hello, world: {request.url.path}")
                                              ^^^^^^^^^^^
  File "aiohttp/_helpers.pyx", line 26, in aiohttp._helpers.reify.__get__
  File "/tmp/aiohttp-issue/.venv/lib/python3.12/site-packages/aiohttp/web_request.py", line 453, in url
    url = URL.build(scheme=self.scheme, host=self.host)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/aiohttp-issue/.venv/lib/python3.12/site-packages/yarl/_url.py", line 386, in build
    _host = _encode_host(host, validate_host=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/aiohttp-issue/.venv/lib/python3.12/site-packages/yarl/_url.py", line 1496, in _encode_host
    raise ValueError(
ValueError: Host 'localhost:8080' cannot contain ':' (at position 9)

Upgrade aiohttp, it works fine

pip install aiohttp==3.10.7
python3 example.py 
babs commented 3 days ago

should be fixed by #2190