Skip to content

Missing 'scheme' key in ws scope #538

Open

Description

@FelixFunk

Environment

python: 3.11.5
aiofiles==23.2.1
blinker==1.8.2
click==8.1.7
Flask==3.0.3
h11==0.14.0
h2==4.1.0
hpack==4.0.0
Hypercorn==0.17.3
hyperframe==6.0.1
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
pathvalidate==3.2.1
priority==2.0.0
PyJWT==2.9.0
pyzmq==26.0.3
Quart==0.19.6
Quart-JWT-Extended==0.1.0
six==1.16.0
Werkzeug==3.0.3
wsproto==1.2.0

OS: OpenSUSE Tumbleweed
Browser: Firefox 132.0.1

CMD

daphne run_service:quart_app -e ssl:44444:privateKey=../dev/ssl/key.pem:certKey=../dev/ssl/cert.pem

Issue

While running a Quart app i get the following stacktrace on a websocket request:

2024-11-06 17:01:34,181 | ERROR: Exception inside application: 'scheme' (server.py:297)
Traceback (most recent call last):
  File "/LOCAL/garcia/Projects/triplaystudio/.venv/lib/python3.11/site-packages/quart/app.py", line 1667, in __call__
    await self.asgi_app(scope, receive, send)
  File "/LOCAL/garcia/Projects/triplaystudio/.venv/lib/python3.11/site-packages/quart/app.py", line 1693, in asgi_app
    await asgi_handler(receive, send)
  File "/LOCAL/garcia/Projects/triplaystudio/.venv/lib/python3.11/site-packages/quart/asgi.py", line 166, in __call__
    websocket = self._create_websocket_from_scope(send)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/LOCAL/garcia/Projects/triplaystudio/.venv/lib/python3.11/site-packages/quart/asgi.py", line 204, in _create_websocket_from_scope
    self.scope["scheme"],
    ~~~~~~~~~~^^^^^^^^^^
KeyError: 'scheme'
10.242.2.5:57258 - - [06/Nov/2024:17:01:34] "WSDISCONNECT /conn" - -

It seems like the 'scheme' property is missing for the websocket connection scope. I am not 100% sure if this issue belongs to daphne, since the asgi documentation marks 'scheme' as an optional setting. However, the documentation also states 'but must not be empty'. If this is indeed related to the Quart project i am really sorry for posting it here. I tested the same code with Hypercorn, so the actual request itself should not be an issue here.

Activity

  1. carltongibson commented on Nov 6, 2024

    @carltongibson
    Member

    As I understand the spec, Optional (but must not be empty); default is "ws". should be read as if provided must not be empty, but optional, defaulting to ws (if not provided).

    It wouldn't hurt to set though if we can get it from the client_scheme. Would it be something you'd be interested to add?

  2. FelixFunk commented on Nov 8, 2024

    @FelixFunk
    Author

    Ok that makes sense. I guess Hypercorn (which was built by a Quart developer) then sets it by default and Quart never checks because of it. Sorry for bothering you then.

    Currently i am on vacation. Also I am fairly new to programming and have never added to a repo before, therefore I am not sure if I am the right fit for this. But I can have a look at it once I am back.

  3. carltongibson commented on Nov 8, 2024

    @carltongibson
    Member

    @FelixFunk Thanks for the reply. Don't feel obliged. Only take it on if that's something you'd enjoy. Have a good holiday!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions