Repository navigation
Closed
Copy link
Labels
c: clientRelates to client codeRelates to client codedeploymentStuff related to running in production containerStuff related to running in production containeronboardingGood for newcomersGood for newcomers
Description
When trying to use BlueapiClient, I got the following error message when trying to run the below:
from blueapi.client import BlueapiClient
bc = BlueapiClient.from_config_file("path/to/config.yaml")
devs = bc.devices
plans = bc.planspython -i /home/xol73553/Documents/BLUESKY/i09_blueapi.py
Traceback (most recent call last):
File "/scratch/bluesky_development/blueapi/venv/lib64/python3.12/site-packages/requests/models.py", line 976, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/json/decoder.py", line 338, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.12/json/decoder.py", line 356, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/xol73553/Documents/BLUESKY/i09_blueapi.py", line 22, in <module>
devs = bc.devices
^^^^^^^^^^
File "/usr/lib64/python3.12/functools.py", line 998, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/venv/lib64/python3.12/site-packages/observability_utils/tracing/decorators.py", line 151, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/src/blueapi/client/client.py", line 307, in devices
return DeviceCache(self._rest)
^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/src/blueapi/client/client.py", line 111, in __init__
for model in rest.get_devices().devices
^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/src/blueapi/client/rest.py", line 162, in get_devices
return self._request_and_deserialize("/devices", DeviceResponse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/venv/lib64/python3.12/site-packages/observability_utils/tracing/decorators.py", line 151, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/src/blueapi/client/rest.py", line 290, in _request_and_deserialize
deserialized = TypeAdapter(target_type).validate_python(response.json())
^^^^^^^^^^^^^^^
File "/scratch/bluesky_development/blueapi/venv/lib64/python3.12/site-packages/requests/models.py", line 980, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The response for devices contains no json, so it provides a JSONDecodeError. The reason the response provides no valid json was because I was not logged in any more.
>>> bc.login()
Logging in
Please login from this URL:- https://identity.diamond.ac.uk/realms/dls/device?user_code=ULED-SLXT
Logged in and cached new token
>>> exit()
Now rerunning the script
python -i /home/xol73553/Documents/BLUESKY/i09_blueapi.py
>>>
It works! But the error message above didn't indicate the issue is due to not being logged in.
Acceptance critera
The client should instead make a check to see if the user is logged in first and then provide a useful error message to the user saying unable to retrieve plans / devices, please login first.
Metadata
Metadata
Assignees
Labels
c: clientRelates to client codeRelates to client codedeploymentStuff related to running in production containerStuff related to running in production containeronboardingGood for newcomersGood for newcomers
Activity
tpoliaw commentedon Apr 7, 2026
I'm pretty sure it should return valid JSON when not logged in. I'm guessing this error is from oauth2-proxy redirecting the request and then returning HTML.
The error could still be improved in the "server returned invalid json" case but I think this is more to do with deployment configuration than blueapi.
[-]BlueapiClient gives unhelpful error message when not logged in[/-][+]BlueapiClient gives unhelpful error message when invalid JSON is returned[/+]tpoliaw commentedon Apr 8, 2026
Steps to reproduce in dev environment
docker compose -f tests/system_tests/compose.yaml up -d(see docs)uv run blueapi -c tests/system_tests/config.yaml servehttp://localhost:4180, leaving the server runninguv run blueapi -c path/to/updated/config.yaml controller plans