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

Failed to fetch VW-Group API tokens, API token request returned with status code 403 #208

Closed
haeuslesbauer opened this issue Aug 31, 2023 · 13 comments

Comments

@haeuslesbauer
Copy link

This script run for 2+ years without problems. But since a few weeks only 1 out of 20 runs were successful. So i thought it would be a good idea to update this library and downloaded the source / installed V4.4.61.

Now i get always the same error and i am no longer able to fetch the data.

DEBUG:asyncio:Using selector: EpollSelector
DEBUG:vw_connection:Using service https://msg.volkswagen.de
DEBUG:vw_connection:Initiating new login
DEBUG:vw_connection:Got authorization endpoint
DEBUG:vw_connection:Authenticating with email and password.
DEBUG:vw_connection:Parsing login response.
DEBUG:vw_connection:Login successful, received authorization code.
DEBUG:vw_connection:Trying to fetch user identity tokens.
DEBUG:vw_connection:User identity token verified OK.
INFO:vw_connection:Successfully logged in
DEBUG:vw_connection:Trying to fetch api tokens.
DEBUG:vw_connection:API token request failed.
ERROR:vw_connection:Failed to fetch VW-Group API tokens, API token request returned with status code 403

I am still able to login to the We Connect app and see the data there as well to the VW portal.
Any idea whats wrong here?

@stuburger
Copy link

Just gonna second this. I am also experiencing the same issue. ☝️

@stickpin
Copy link
Collaborator

stickpin commented Sep 1, 2023

Same story in Home Assistant.
Today not able to make it work at all. :(
WeConnect App works fine.

2023-09-01 17:42:26.390 INFO (MainThread) [volkswagencarnet.vw_connection] Successfully logged in
2023-09-01 17:42:26.416 ERROR (MainThread) [volkswagencarnet.vw_connection] Failed to fetch VW-Group API tokens, API token request returned with status code 403
2023-09-01 17:42:26.417 ERROR (MainThread) [custom_components.volkswagencarnet.config_flow] Failed to login due to error: 'vwg'

@StefanoGiu
Copy link

Following...

@willemvanlent
Copy link

This might be interesting:
trocotronic/weconnect@863df6e

@virtualdj
Copy link

This might be interesting: trocotronic/weconnect@863df6e

I've tried running the example script on the home-page with #209 and placed a breakpoint on line 382 _getAPITokens(self) and line 634 getRealCarData, the latter which has the modified URL.
The second breakpoint is never reached, because the script fails on `_getAPITokens(self)

DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:volkswagencarnet.vw_connection:Using service https://msg.volkswagen.de
DEBUG:volkswagencarnet.vw_connection:Initiating new login
DEBUG:volkswagencarnet.vw_connection:Got authorization endpoint
DEBUG:volkswagencarnet.vw_connection:Authenticating with email and password.
DEBUG:volkswagencarnet.vw_connection:Parsing login response.
DEBUG:volkswagencarnet.vw_connection:Login successful, received authorization code.
DEBUG:volkswagencarnet.vw_connection:Trying to fetch user identity tokens.
DEBUG:volkswagencarnet.vw_connection:Failed to verify token, error: module 'jwt.algorithms' has no attribute 'RSAAlgorithm'
WARNING:volkswagencarnet.vw_connection:User identity token could not be verified!
INFO:volkswagencarnet.vw_connection:Successfully logged in
DEBUG:volkswagencarnet.vw_connection:Trying to fetch api tokens.
DEBUG:volkswagencarnet.vw_connection:API token request failed.
ERROR:volkswagencarnet.vw_connection:Failed to fetch VW-Group API tokens, API token request returned 
with status code 403

@beschoenen
Copy link
Contributor

beschoenen commented Sep 5, 2023

Did some research on this, and seems like the hardcoded client id XCLIENT_ID is expired on VW's side.
I generated a new one using a snippet from weconnect, and the example file from the readme works again now.

diff --git a/volkswagencarnet/vw_const.py b/volkswagencarnet/vw_const.py
index a63951e..f64528d 100644
--- a/volkswagencarnet/vw_const.py
+++ b/volkswagencarnet/vw_const.py
@@ -28,7 +28,7 @@ CLIENT = {
 }
 
 
-XCLIENT_ID = "85fa2187-5b5c-4c35-adba-1471d0c4ea60"
+XCLIENT_ID = "c8fcb3bf-22d3-44b0-b6ce-30eae0a4986f"
 XAPPVERSION = "5.3.2"
 XAPPNAME = "We Connect"
 USER_AGENT = "okhttp/3.14.7"

weconnect has an interesting approach generating a new client for each session, maybe that's something we should implement, too.
Check out this snippet to see how it works.
https://github.com/trocotronic/weconnect/blob/master/NativeAPI.py#L429-L442

Proof:

name: WVWZZZAUZJW80**** Service inspection days
str_state: -4 days
state: -4
supported: True
attr: service_inspection
attributes: {}
name: WVWZZZAUZJW80*** Charging time left
str_state: 0 min
state: 0
supported: True
attr: charging_time_left
attributes: {}
name: WVWZZZAUZJW80*** Combustion range
str_state: 520 km
state: 520
supported: True
attr: combustion_range
attributes: {}

@stickpin
Copy link
Collaborator

stickpin commented Sep 5, 2023

Did some research on this, and seems like the hardcoded client id XCLIENT_ID is expired on VW's side. I generated a new one using a snippet from weconnect, and the example file from the readme works again now.

diff --git a/volkswagencarnet/vw_const.py b/volkswagencarnet/vw_const.py
index a63951e..f64528d 100644
--- a/volkswagencarnet/vw_const.py
+++ b/volkswagencarnet/vw_const.py
@@ -28,7 +28,7 @@ CLIENT = {
 }
 
 
-XCLIENT_ID = "85fa2187-5b5c-4c35-adba-1471d0c4ea60"
+XCLIENT_ID = "c8fcb3bf-22d3-44b0-b6ce-30eae0a4986f"
 XAPPVERSION = "5.3.2"
 XAPPNAME = "We Connect"
 USER_AGENT = "okhttp/3.14.7"

weconnect has an interesting approach generating a new client for each session, maybe that's something we should implement, too. Check out this snippet to see how it works. https://github.com/trocotronic/weconnect/blob/master/NativeAPI.py#L429-L442

Proof:

name: WVWZZZAUZJW80**** Service inspection days
str_state: -4 days
state: -4
supported: True
attr: service_inspection
attributes: {}
name: WVWZZZAUZJW80*** Charging time left
str_state: 0 min
state: 0
supported: True
attr: charging_time_left
attributes: {}
name: WVWZZZAUZJW80*** Combustion range
str_state: 520 km
state: 520
supported: True
attr: combustion_range
attributes: {}

I can confirm that the new client ID also works for me.
Thanks @beschoenen!

@StefanoGiu
Copy link

Hi all, I changed the XCLIENT_ID to "c8fcb3bf-22d3-44b0-b6ce-30eae0a4986f". With the integration "Volkswagen WeConnect" I still get the below error:

[volkswagencarnet.vw_connection] Failed to fetch VW-Group API tokens, API token request returned with status code 403

@stickpin
Copy link
Collaborator

stickpin commented Sep 5, 2023

Hi all, I changed the XCLIENT_ID to "c8fcb3bf-22d3-44b0-b6ce-30eae0a4986f". With the integration "Volkswagen WeConnect" I still get the below error:

[volkswagencarnet.vw_connection] Failed to fetch VW-Group API tokens, API token request returned with status code 403

You need to clean __pycache and if you use Home Assistant you need to restart it.

@beschoenen
Copy link
Contributor

Hi all, I changed the XCLIENT_ID to "c8fcb3bf-22d3-44b0-b6ce-30eae0a4986f". With the integration "Volkswagen WeConnect" I still get the below error:

[volkswagencarnet.vw_connection] Failed to fetch VW-Group API tokens, API token request returned with status code 403

Test with the new 4.4.65 release!

@StefanoGiu
Copy link

Actually it works now... I had to change the XCLIENT_ID under ".homeassistant\deps\Python311\site-packages\volkswagencarnet\vw_const.py" path... and not the one under Python folder

@artspb
Copy link

artspb commented Sep 5, 2023

4.4.65 works like a charm. Thanks so much for the prompt fix!

@dkitz
Copy link

dkitz commented Sep 5, 2023

For all who had the 403 error, please check you have the right media!

This version, 4.4.65 works perfect again! Thank you for all the effort.

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

10 participants