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

WebSocket client does not support query component #5868

Closed
1 task done
hoh opened this issue Jul 9, 2021 · 0 comments
Closed
1 task done

WebSocket client does not support query component #5868

hoh opened this issue Jul 9, 2021 · 0 comments
Labels

Comments

@hoh
Copy link
Contributor

hoh commented Jul 9, 2021

Describe the bug

According to rfc6455 section 11.1.1, a "ws" URI Scheme supports a query component with the URI scheme syntax "ws:" "//" authority path-abempty [ "?" query ].

While the query component can be defined in ClienSession.request using the params argument, this argument is absent from ClientSession.ws_connect.

This requires users of ws_connect to build and embed the query component in the url agument of `ws_connect.

To Reproduce

Try running the following example:

async def main():
    params = {'key1': 'value1', 'key2': 'value2'}
    async with aiohttp.ClientSession() as session:
        async with session.ws_connect('http://example.org/ws', params=params) as ws:
            async for msg in ws:
                if msg.type == aiohttp.WSMsgType.TEXT:
                    if msg.data == 'close cmd':
                        await ws.close()
                        break
                    else:
                        await ws.send_str(msg.data + '/answer')
                elif msg.type == aiohttp.WSMsgType.ERROR:
                    break
                    
import asyncio, aiohttp
asyncio.run(main())

Expected behavior

The expected result is a response for the url http://example.org/ws?key1=value1&key2=value2.

Using the example target, this would give:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "<input>", line 4, in do
  File "/home/hugo/Repos/Aleph/aiohttp/aiohttp/client.py", line 1072, in __aenter__
    self._resp = await self._coro
  File "/home/hugo/Repos/Aleph/aiohttp/aiohttp/client.py", line 755, in _ws_connect
    raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 404, message='Invalid response status', url=URL('http://example.org/ws?key1=value1&key2=value2')

Logs/tracebacks

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "<input>", line 4, in do
TypeError: ws_connect() got an unexpected keyword argument 'params'


### Python Version

```console
Python 3.8.8

aiohttp Version

aiohttp master on commit 3d73221072c350d973b2fb0c54c78ad30863d433

multidict Version

Name: multidict
Version: 5.1.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /opt/venv/aiohttp/lib/python3.8/site-packages
Requires: 
Required-by: yarl

yarl Version

Name: yarl
Version: 1.6.3
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /opt/venv/aiohttp/lib/python3.8/site-packages
Requires: multidict, idna
Required-by:

OS

Linux 5.10.0-7-amd64 #1 SMP Debian 5.10.40-1 (2021-05-28) x86_64 GNU/Linux

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct
@hoh hoh added the bug label Jul 9, 2021
asvetlov added a commit that referenced this issue Oct 27, 2021
* Fix URL params were unavailable in ws_connect (#5868)

* Update CHANGES/5868.bugfix

Co-authored-by: Anes Abismail <[email protected]>

* Update 5868.bugfix

Co-authored-by: Anes Abismail <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
asvetlov added a commit that referenced this issue Oct 27, 2021
* Fix URL params were unavailable in ws_connect (#5868)

* Update CHANGES/5868.bugfix

Co-authored-by: Anes Abismail <[email protected]>

* Update 5868.bugfix

Co-authored-by: Anes Abismail <[email protected]>
Co-authored-by: Andrew Svetlov <[email protected]>
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

2 participants