labthings / labthings-picamera2

A LabThings-FastAPI Thing for working with picamera2
GNU Lesser General Public License v2.1
1 stars 2 forks source link

GET `/camera/camera_configuration` returns an error #12

Open julianstirling opened 1 week ago

julianstirling commented 1 week ago

Terminal log:

INFO:     192.168.178.28:49834 - "GET /camera/camera_configuration HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
               ^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 327, in app
    content = await serialize_response(
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/fastapi/routing.py", line 181, in serialize_response
    return field.serialize(
           ^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/fastapi/_compat.py", line 150, in serialize
    return self._type_adapter.dump_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/pydantic/type_adapter.py", line 135, in wrapped
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/openflexure/application/openflexure-microscope-server/.venv/lib/python3.11/site-packages/pydantic/type_adapter.py", line 451, in dump_python
    return self.serializer.to_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'libcamera._libcamera.Transform'>
rwb27 commented 1 week ago

This will be caused by objects in the configuration dict returned by picamera2 not being JSON serialisable. We could either use a Pydantic model to describe the return value or (easier) just have some code that turns the libcamera Transform object into a list of numbers or similar.

rwb27 commented 1 week ago

If there's a way to get friendlier messages out of the web app, I'd love to implement it! Unfortunately that error comes from FastAPI/Pydantic, so it's not one I can easily intercept.