starlette icon indicating copy to clipboard operation
starlette copied to clipboard

docs: note about websocket support in uvicorn

Open sminnee opened this issue 7 months ago • 4 comments

Summary

Docs update.

This small gotcha stumped me for a few hours and I thought it worth adding to the documentation. The separation of responsibility between uvicorn and Starlette wasn't self-evident.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • N/A I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

sminnee avatar May 11 '25 22:05 sminnee

Not sure why a docs update is failing the build, sorry!

sminnee avatar May 11 '25 22:05 sminnee

Not a problem with this change, was able to reproduce this locally on the master branch using pyenv. Will dig around some more and try to submit a PR to fix.

$ git rev-parse --short HEAD
4acf1d1

(venv) $ python3 --version
Python 3.14.0b1

(venv) $ ./scripts/check
...
TypeError: AugmentedHelpFormatter.__init__() got an unexpected keyword argument 'prefix_chars'

Switch to 3.13.1 and it passes:

$ rm -rf venv/

$ pyenv shell system
$ python3 --version
Python 3.13.1

$ python3 -m venv venv
$ ./scripts/install

$ source venv/bin/activate
(venv) $ python3 --version
Python 3.13.1

(venv) $ ./scripts/check
...
All checks passed!

AllenSH12 avatar May 14 '25 16:05 AllenSH12

@Kludex perhaps it is not worth including 3.14 yet (or marking it optional)?

It took 5 months to get from v3.13.0b1 to v3.13.0 and mypy is not testing against 3.14 yet, would be a shame to have failing tests for such a potentially long time, even if 3.14.0a7 initially worked...

AllenSH12 avatar May 14 '25 18:05 AllenSH12

@Kludex perhaps it is not worth including 3.14 yet (or marking it optional)?

It took 5 months to get from v3.13.0b1 to v3.13.0 and mypy is not testing against 3.14 yet, would be a shame to have failing tests for such a potentially long time, even if 3.14.0a7 initially worked...

We can skip the type checker on 3.14, yep.

Kludex avatar May 14 '25 20:05 Kludex

I don't think this comment is needed. It seems a problem with the ASGI server - it should provide a better error message!

Happy to discuss this over Uvicorn.

Kludex avatar Jul 12 '25 07:07 Kludex

I was trying to help the next person who hit the snag I found, with a few sentences of documentation, but this is too hard.

I'm not sure how the AGSI server not configured to support websockets will know that not supporting websockets is an error.

Just in case it was missed (it had no reply), I had redrafted the proposed change:

For websockets to work, the ASGI web server that calls Starlette will also need support for websockets. For example, uvicorn will need either the wsproto or websockets PyPI package installed. Without this, Starlette will respond with 404 errors on the websocket endpoints.

sminnee avatar Jul 14 '25 09:07 sminnee