diff --git a/docs/source/quickstart/counter.py b/docs/source/quickstart/counter.py index 48dbc415..187bb887 100644 --- a/docs/source/quickstart/counter.py +++ b/docs/source/quickstart/counter.py @@ -34,4 +34,4 @@ def slowly_increase_counter(self) -> None: server = lt.ThingServer({"counter": TestThing}) # We run the server using `uvicorn`: - uvicorn.run(server.app, port=5000) + uvicorn.run(server.app, port=5000, ws="websockets-sansio") diff --git a/docs/source/tutorial/writing_a_thing.rst b/docs/source/tutorial/writing_a_thing.rst index 3be425d1..cda1e5f8 100644 --- a/docs/source/tutorial/writing_a_thing.rst +++ b/docs/source/tutorial/writing_a_thing.rst @@ -35,7 +35,7 @@ Our first Thing will pretend to be a light: we can set its brightness and turn i if __name__ == "__main__": import uvicorn # We run the server using `uvicorn`: - uvicorn.run(server.app, port=5000) + uvicorn.run(server.app, port=5000, ws="websockets-sansio") If you visit `http://localhost:5000/light`, you will see the Thing Description. You can also interact with it using the OpenAPI documentation at `http://localhost:5000/docs`. If you visit `http://localhost:5000/light/brightness`, you can set the brightness of the light, and if you visit `http://localhost:5000/light/is_on`, you can see whether the light is on. Changing values on the server requires a ``PUT`` or ``POST`` request, which is easiest to do using the OpenAPI "Try it out" feature. Check that you can use a ``POST`` request to the ``toggle`` endpoint to turn the light on and off. diff --git a/src/labthings_fastapi/server/cli.py b/src/labthings_fastapi/server/cli.py index 66f854cd..a97c7701 100644 --- a/src/labthings_fastapi/server/cli.py +++ b/src/labthings_fastapi/server/cli.py @@ -161,7 +161,7 @@ def serve_from_cli( server = ThingServer.from_config(config, True if args.debug else False) if dry_run: return server - uvicorn.run(server.app, host=args.host, port=args.port) + uvicorn.run(server.app, host=args.host, port=args.port, ws="websockets-sansio") except BaseException as e: if args.fallback: print(f"Error: {e}") @@ -174,7 +174,7 @@ def serve_from_cli( ) ) - uvicorn.run(app, host=args.host, port=args.port) + uvicorn.run(app, host=args.host, port=args.port, ws="websockets-sansio") else: if isinstance(e, (ValidationError, ThingImportFailure)): print(f"Error reading LabThings configuration:\n{e}") diff --git a/tests/test_fallback.py b/tests/test_fallback.py index 56a367f1..e3a1136f 100644 --- a/tests/test_fallback.py +++ b/tests/test_fallback.py @@ -170,7 +170,7 @@ def test_actual_server_fallback(): # Starting the server is a SystemExit with pytest.raises(SystemExit, match="3") as excinfo: - uvicorn.run(server.app, port=5000) + uvicorn.run(server.app, port=5000, ws="websockets-sansio") server_error = excinfo.value assert server.startup_failure is not None assert server.startup_failure["thing"] == "bad_thing" diff --git a/tests/test_mjpeg_stream.py b/tests/test_mjpeg_stream.py index 0effde36..f00b43b1 100644 --- a/tests/test_mjpeg_stream.py +++ b/tests/test_mjpeg_stream.py @@ -78,4 +78,4 @@ def test_mjpeg_stream(client): assert isinstance(telly, Telly) telly.framerate = 6 telly.frame_limit = -1 - uvicorn.run(server.app, port=5000) + uvicorn.run(server.app, port=5000, ws="websockets-sansio")