robberwick / pylibrelinkup

`pylibrelinkup` is a Python client for the LibreLinkUp API, which allows you to interact with the LibreLinkUp service to retrieve glucose data and other related information. This project is a Python implementation inspired by the [libre-link-up-api-client](https://github.com/DiaKEM/libre-link-up-api-client) project.
MIT License
2 stars 0 forks source link

pydantic_core._pydantic_core.ValidationError: 1 validation error for ConnectionResponse #32

Open Kanzll opened 1 week ago

Kanzll commented 1 week ago

Hello, I get a validation error when using read method, here is my code

from pylibrelinkup import PyLibreLinkUp

client = PyLibreLinkUp(email='xxx', password='xxx')
client.authenticate()
patient_list = client.get_patients()
patient = patient_list[0]
print(patient.patient_id)
patient_data = client.read(patient_identifier=patient.patient_id)
print(f"Current glucose: {patient_data.current}")

And here is complete error message:

Traceback (most recent call last):
  File "/Users/uu/Documents/Coding/libreview/main.py", line 8, in <module>
    patient_data = client.read(patient_identifier=patient.patient_id)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.12/site-packages/pylibrelinkup/pylibrelinkup.py", line 111, in read
    return ConnectionResponse.model_validate(response_json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.12/site-packages/pydantic/main.py", line 596, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ConnectionResponse
data.connection.alarmRules.c
  Field required [type=missing, input_value={'h': {'on': True, 'th': ...': 5, 'r': 5, 'std': {}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.9/v/missing

Thank you !

robberwick commented 1 week ago

it looks like the c field in the data.connection.alarmRules is missing. from your response. let's go ahead and just default that in the case where it's not present.

robberwick commented 1 week ago

Thanks for the report @Kanzll - i've used that traceback to reproduce the issue here, and prepped a fix branch. You can give it a try here:

pip uninstall pylibrelinkup
python -m pip install git+https://github.com/robberwick/pylibrelinkup.git@handle_missing_alarm_rules_c
Kanzll commented 1 week ago

Yes ! it works, thank you again @robberwick

robberwick commented 1 week ago

Awesome! We got there in the end :+1:

And thank you for your patience @Kanzll , and also those example response payloads. They've helped me to identify places where I can strengthen some weak spots in the library, and even some areas where I can add new functionality.

robberwick commented 1 week ago

this should be fixed in v0.5.1 - https://pypi.org/project/pylibrelinkup/0.5.1/

Kanzll commented 1 week ago

this should be fixed in v0.5.1 - https://pypi.org/project/pylibrelinkup/0.5.1/

Thank you @robberwick