ondrej1024/carelink-python-client

:INFO]_get_data() Expecting value: line 1 column 1 (char 0)

Opened this issue · 11 comments

Running carelink_client2_cli.py (or the proxy) gives the following error:
:INFO]_get_data()
Expecting value: line 1 column 1 (char 0)

Do you have some more info? Maybe the complete log.
What kind of account are you using (carepartner or patient)?
What country are you in?
Does the program crash or does it continue to run?

Hello, my country is HU, I'm using a carepartner acccount, but I tried with patient and I got the same error and the program crashes.
This is my full log (xxx is my personal data):

python3 carelink_client2_cli.py -d -v
Client created
[2024-02-27 21:03:14:INFO] _read_token_file()
[2024-02-27 21:03:14:INFO] _get_access_token_payload()
[2024-02-27 21:03:14:INFO] _get_config()
[2024-02-27 21:03:15:INFO] _get_user()
[2024-02-27 21:03:16:INFO] _get_patient()
User Info:
user: xxx(xxx)
role: CARE_PARTNER_OUS
country: HU
patient: xxx (xxx)
Starting download, count: 1
[2024-02-27 21:03:16:INFO] _is_token_valid()
[2024-02-27 21:03:16:INFO] access token expires in 10955s (Wed Feb 28 00:05:52 UTC 2024)
[2024-02-27 21:03:16:INFO] _get_data()
Expecting value: line 1 column 1 (char 0)

Thanks for trying to help!

You could try to enable the DEBUG log level by changing line 68 in carelink_client2.py

log.basicConfig(format=FORMAT, datefmt='%Y-%m-%d %H:%M:%S', level=log.INFO)

Maybe the additional information will give us some idea of what is happening.

Furthermore you can disable the try except statement in carelink_client2_cli.py . so when the exception occurs it will not be caught and you will get a detailed error description which you can post here.

Client created
[2024-03-03 15:08:06:INFO] _read_token_file()
[2024-03-03 15:08:06:INFO] _get_access_token_payload()
[2024-03-03 15:08:06:INFO] _get_config()
[2024-03-03 15:08:06:DEBUG] Starting new HTTPS connection (1): clcloud.minimed.com:443
[2024-03-03 15:08:07:DEBUG] https://clcloud.minimed.com:443 "GET /connect/carepartner/v6/discover/android/3.1 HTTP/1.1" 200 15100
[2024-03-03 15:08:07:DEBUG] status: 200
[2024-03-03 15:08:07:DEBUG] region: EU
[2024-03-03 15:08:07:DEBUG] Starting new HTTPS connection (1): carelink.minimed.eu:443
[2024-03-03 15:08:07:DEBUG] https://carelink.minimed.eu:443 "GET /configs/v1/eu_sso_cp_eu_v5.json HTTP/1.1" 200 4633
[2024-03-03 15:08:07:DEBUG] status: 200
[2024-03-03 15:08:07:INFO] _get_user()
[2024-03-03 15:08:07:DEBUG] Starting new HTTPS connection (1): carelink.minimed.eu:443
[2024-03-03 15:08:07:DEBUG] https://carelink.minimed.eu:443 "GET /api/carepartner/v2/users/me HTTP/1.1" 401 48
[2024-03-03 15:08:07:DEBUG] status: 401
[2024-03-03 15:08:07:ERROR] 'role'
[2024-03-03 15:08:07:INFO] _do_refresh()
[2024-03-03 15:08:07:DEBUG] Starting new HTTPS connection (1): mdtlogin-ocl.medtronic.com:443
[2024-03-03 15:08:08:DEBUG] https://mdtlogin-ocl.medtronic.com:443 "POST /mmcl/auth/oauth/v2/token HTTP/1.1" 200 1013
[2024-03-03 15:08:08:DEBUG] status: 200
[2024-03-03 15:08:08:INFO] _get_access_token_payload()
[2024-03-03 15:08:08:INFO] _write_token_file()
[2024-03-03 15:08:08:INFO] _read_token_file()
[2024-03-03 15:08:08:INFO] _get_access_token_payload()
[2024-03-03 15:08:08:INFO] _get_config()
[2024-03-03 15:08:08:DEBUG] Starting new HTTPS connection (1): clcloud.minimed.com:443
[2024-03-03 15:08:08:DEBUG] https://clcloud.minimed.com:443 "GET /connect/carepartner/v6/discover/android/3.1 HTTP/1.1" 200 15100
[2024-03-03 15:08:08:DEBUG] status: 200
[2024-03-03 15:08:08:DEBUG] region: EU
[2024-03-03 15:08:08:DEBUG] Starting new HTTPS connection (1): carelink.minimed.eu:443
[2024-03-03 15:08:09:DEBUG] https://carelink.minimed.eu:443 "GET /configs/v1/eu_sso_cp_eu_v5.json HTTP/1.1" 200 4633
[2024-03-03 15:08:09:DEBUG] status: 200
[2024-03-03 15:08:09:INFO] _get_user()
[2024-03-03 15:08:09:DEBUG] Starting new HTTPS connection (1): carelink.minimed.eu:443
[2024-03-03 15:08:09:DEBUG] https://carelink.minimed.eu:443 "GET /api/carepartner/v2/users/me HTTP/1.1" 200 366
[2024-03-03 15:08:09:DEBUG] status: 200
[2024-03-03 15:08:09:INFO] _get_patient()
[2024-03-03 15:08:09:DEBUG] Starting new HTTPS connection (1): carelink.minimed.eu:443
[2024-03-03 15:08:09:DEBUG] https://carelink.minimed.eu:443 "GET /api/carepartner/v2/links/patients HTTP/1.1" 200 236
[2024-03-03 15:08:09:DEBUG] status: 200
User Info:
user: XXX (XXX)
role: CARE_PARTNER_OUS
country: HU
patient: XXX (XXX)
Starting download, count: 1
[2024-03-03 15:08:09:INFO] _is_token_valid()
[2024-03-03 15:08:09:INFO] access token expires in 10976s (Sun Mar 03 18:11:06 UTC 2024)
[2024-03-03 15:08:09:INFO] _get_data()
[2024-03-03 15:08:09:DEBUG] Starting new HTTPS connection (1): clcloud.minimed.eu:443
[2024-03-03 15:08:09:DEBUG] https://clcloud.minimed.eu:443 "POST /connect/carepartner/v6/display/message HTTP/1.1" 204 0
[2024-03-03 15:08:09:DEBUG] status: 204
Traceback (most recent call last):
File "/home/ubuntu/cnew/carelink_client2_cli.py", line 74, in
recentData = client.getRecentData()
File "/home/ubuntu/cnew/carelink_client2.py", line 383, in getRecentData
data = self._get_data(self.__config,
File "/home/ubuntu/cnew/carelink_client2.py", line 228, in _get_data
return resp.json()
File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The request to download the pump data from the Carelink API produces a response status code 204 - No Content. That means there is no data in the response and the attempt to decode it fails.

I have no idea why the Carelink server doesn't send any data in your case. Do you get data with the official Carelink app?

Official carelink website is working. I only use a sensor with the Guardian Connect app.
Now I've successfully get the old version to work, so if this won't work I'll use that.
I'd be happy if the new one works, but if it doesn't, thanks for the help anyway.

That would explain things. I don't have your setup (using a 780G pump with sensor) here, so unfortunately I cannot test this. But I guess that the API endpoint for fetching the sensor data is different when using just the sensor. Maybe @palmarci has some information on this.

I discovered some kind of android stuff in the carelink_client2.py but I don't understand everything, but maybe that's why the old one worked because it used some firefox stuff. Preveously you asked the Carelink app, maybe you meant the phone application, and that isn't working, because my sernsor device isn't supported. (I totally forget, there is a carelink app)

Exactly, the new carelink_client2.py now uses the same API which is used by the Carelink Connect app, which is probably not compatible with the Guardian connect app

The old Carelink Client used the API from the Carelink Web UI, which is probably the same for both insulin pumps and standalone sensors.

I have a 780 pump with a sensor and i cannot seem to use the Carelink Web UI, it prompts me to use the Carelink Connect mobile app, however your scripts work fine @ondrej1024, so this is just a "frontend" limitation :)

When i was researching this i only had a sensor, and the initial script was written for that. The response format is definitely not the same, however as far as i remember the endpoints are the same.

@palmarci
In your original login script you used this endpoint for downloading the data:
/patient/connect/data

But in the new carelink client we use this endpoint:
/connect/carepartner/v6/display/message

This is probably not working for the sensor only setup. So this case will have to be handled separately.