Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration stopped working & cannot login anymore: 'auth_tmp_token' error #46

Closed
GertVanderstukken opened this issue Aug 19, 2023 · 22 comments

Comments

@GertVanderstukken
Copy link

The integration suddenly stopped working somewhere yesterday.
I have to say that I also had some issues on the app on my mobile for some time before that, so I figured it to be a general problem @ Medtronic.

Then the app on my mobile started working again, however the HA integration was not.

I tried to remove and re-add the integration, but when I try to complete the credential window, I get "bad username/password" (but I'm "sure" it's OK).

Anybody else with this problem?

This is in the logs:
2023-08-19 00:32:21.165 ERROR (MainThread) [custom_components.carelink] Unexpected error fetching carelink data: 'auth_tmp_token' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/carelink/__init__.py", line 149, in _async_update_data recent_data = await self.client.get_recent_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/carelink/api.py", line 468, in get_recent_data if await self.__get_authorization_token() is not None: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/carelink/api.py", line 430, in __get_authorization_token auth_token = self.async_client.cookies[CARELINK_AUTH_TOKEN_COOKIE_NAME] ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 1148, in __getitem__ raise KeyError(name) KeyError: 'auth_tmp_token' 2023-08-19 00:32:21.173 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Carelink' for carelink integration not ready yet: 'auth_tmp_token'; Retrying in background

@GertVanderstukken GertVanderstukken changed the title Cannot login Integration stopped working & cannot login anymore: 'auth_tmp_token' error Aug 19, 2023
@GertVanderstukken
Copy link
Author

Just to know: Is anybody else experiencing the same issue?
Or is it just me :( ?

@yo-han
Copy link
Owner

yo-han commented Aug 21, 2023

Hi @GertVanderstukken. I've never seen this issue before. What version of Home Assistant are you using and what version of this integration? Are they both up to date?

@GertVanderstukken
Copy link
Author

Hey, strange...

I'm on the latest version of everything:

Home Assistant 2023.8.3
Supervisor 2023.08.1
Operating System 10.5
Frontend-versie: 20230802.1 - latest

HACS: 1.32.1
Carelink Integration: 2023.7.0

@GertVanderstukken
Copy link
Author

OK, I did some more testing on a Home-Assistant instance I had powered off for some time, that is based on docker.

When I start it with a container running Home-Assistant version 2023.5.3, it runs OK.
When I start it using a 2023.5.4 container, it fails.
image
image

Stopping and restarting 2023.5.3 => OK again.
image
image

What version of Home Assistant are you running ?

@GertVanderstukken
Copy link
Author

I just installed a complete new Home Assistant server, installed HACS & Carelink integration => not working.
Very strange. Nobody else with this problem?

@yo-han
Copy link
Owner

yo-han commented Aug 22, 2023

I'm running the integration in the latest available version now. Maybe I can test some other versions tonight, I know there are some changes done to Home Assistant this year that had an impact on the integration but they are never in minor releases (e.g. 2023.8.2) but only in the major ones (e.g. 2023.8.0).

There you got seems to occur when no session is setup with metronic after login. Not sure why this only seems to happen to you.

@bvdkerkhof
Copy link

I can confirm i have the same issue, also the temp token issue.

Running the HA Core 2023.8.3 version on Python 3.11 on Raspbian. If you need more info let me know i'm happy to do some debug logging

@yo-han
Copy link
Owner

yo-han commented Aug 22, 2023

Jup, got it now too after a reboot. Not sure where this comes from but now I have a starting point at least.

@GertVanderstukken
Copy link
Author

At least I'm not alone anymore. Welcome to the club :)

@pops3449
Copy link

Same issue
image
Home Assistant 2023.8.3
Supervisor 2023.08.1
Operating System 10.4
Frontend 20230802.1 - latest

@yo-han
Copy link
Owner

yo-han commented Aug 22, 2023

I did a quick test with the original client lib I used (https://github.com/ondrej1024/carelink-python-client) and it has the same problem. I guess something changed in the login process again.

It can also have something to do with the python version 3.11. Is there anyone still running on python 3.10 and running a working installation of the latest version of this integration?

@niemczuk
Copy link

User-Agent data was modified in the xDRIP application and it started logging in correctly: NightscoutFoundation/xDrip@22954b7

@GertVanderstukken
Copy link
Author

GertVanderstukken commented Aug 22, 2023

OK, I found a way to make it work.
in api.py, I changed line 94:
self.__common_headers = {}
into:

self.__common_headers = {
    "Accept-Language":"en;q=0.9, *;q=0.8",
    "Connection":"keep-alive",
    "sec-ch-ua":"\"Google Chrome\";v=\"115\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"115\"",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
    "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
}

rebooted and all started working.

I based myself on "carelink_client.py" - line 78 (https://github.com/ondrej1024/carelink-python-client).
Also in there, they mention:
# 09/05/2023 - Fix connection issues by removing common http headers
But....
I'm NOT a developer, so I'm not sure if this is the right thing ...

@niemczuk
Copy link

I corrected the code you wrote in the api.py file and everything works fine now - good job.

@yo-han
Copy link
Owner

yo-han commented Aug 22, 2023

Hmmm. These headers are removed in pr #39 because it made the login not work. Not completely sure if this is the final solution.

@sedy89
Copy link
Contributor

sedy89 commented Aug 23, 2023

hi @yo-han ,
as @niemczuk mentioned, a very similar change was taken into xdrip to fix the communication after the latest carelink server update NightscoutFoundation/xDrip#3029.
They did not just add back the common headers, but they updated the chrome user agent to the latest version number. Seems to be required after the latest medtronic server update.

@yo-han
Copy link
Owner

yo-han commented Aug 23, 2023

Yes I noticed. But what I don't understand is why a version of a browser would be a factor for Medtronic to not let someone login. This is the second time these headers are the source of issues where users cannot login anymore. For now we can restore them, but I would like to know what the real reason is they need to be updated.

Why would Chrome/112 be an issue? It's a release from may this year. A version like Chrome/87 would make more sense.

@yo-han
Copy link
Owner

yo-han commented Aug 23, 2023

I made a beta release with a possible fix. If anyone wants to test it please activate beta releases for this integration in Home Assistant and pull new updates.

https://github.com/yo-han/Home-Assistant-Carelink/releases/tag/2023.8.0-b1

@hhuitema
Copy link

Works for my install.

Ps my theory is that Medtronic was implementing updates on the Auth services. But the last Weeks there were quite a few outages, so maybe they opted to go back to something more reliable..

@bvdkerkhof
Copy link

I made a beta release with a possible fix. If anyone wants to test it please activate beta releases for this integration in Home Assistant and pull new updates.

https://github.com/yo-han/Home-Assistant-Carelink/releases/tag/2023.8.0-b1

The beta also solves the issue for me

@yo-han
Copy link
Owner

yo-han commented Aug 24, 2023

Allright. A new release is available for everyone now. It worked for me I several version too so this must be it for now.

@GertVanderstukken
Copy link
Author

Yes, the new release is working for me.
Thanks!

@yo-han yo-han closed this as completed Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants