jamesremuscat / pyze

Unofficial Python client and API for Renault ZE
MIT License
111 stars 29 forks source link

Error communicating with Renault API #95

Open timmchugh11 opened 3 years ago

timmchugh11 commented 3 years ago

Hello,

About 2 days ago my connection stopped working and I get the error,

Error communicating with Renault API! {"error":"access_denied","error_description":"Unauthorized"}

Is this an issue with pyze? I have tried re adding my credentials and I get the same error when logging in.

I am still able to use the Renault app and the data is up to date, so I don't think it is my account.

Thanks

epenet commented 3 years ago

There was a change of Key on the Renault servers. There is a discussion about it on https://github.com/hacf-fr/renault-api/issues/181, with corresponding pull request https://github.com/hacf-fr/renault-api/pull/182

timmchugh11 commented 3 years ago

Thank you, I just used the new key and all is working again

The key I used from the link you sent, Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2

yannickh commented 3 years ago

Hmm, I got it working again with the new key, but it seems to have broken again?

Error message seems to be slightly different though. When using the new key (mentioned above), I get this error: {"type":"FUNCTIONAL","messages":[{"code":"err.func.wired.unauthorized","message":"The access is unauthorized"}],"errors":[{"errorCode":"err.func.wired.unauthorized","errorMessage":"The access is unauthorized"}],"error_reference":"FUNCTIONAL"}

While when I use a different/incorrect key, I get this error: {"error":"access_denied","error_description":"Unauthorized"}

Any ideas? The My Renault app on my phone still functions correctly...

db-EV commented 3 years ago

Problem maybe related to https://github.com/jamesremuscat/pyze/issues/78?

epenet commented 3 years ago

Note: https://github.com/hacf-fr/renault-api still works, but in my case the data hasn't changed since 2021-02-07T12:17:58+01:00 and no longer reflects the reality.

db-EV commented 3 years ago

Ok, I found the problem in EVCC code. Was not a problem on Renaults side... So API (with updated Kamereon key) still works fine here. After vehicle wakeup the data was updated correctly.

Yes, it seems to be some faulty Gigya integrations out there.

fungus75 commented 3 years ago

Ok, I found the problem in EVCC code. Was not a problem on Renaults side... So API (with updated Kamereon key) still works fine here. After vehicle wakeup the data was updated correctly.

Yes, it seems to be some faulty Gigya integrations out there.

Starting with today 12:00 CET gigya changed (or never accepted) some parameter-names. See (sorry german) https://github.com/fungus75/ioBroker.zoe2/issues/17 or have a look at the implementation of the gigya-part here: https://github.com/hacf-fr/renault-api/issues

fungus75 commented 3 years ago

Please find here which parameter I had to adjust: https://github.com/fungus75/ioBroker.zoe2/commit/c787fda42de51d7f7df4a087706ed1a67e55cd9c

db-EV commented 3 years ago

And calling account.getAccount is unnecessary, it's enough with accounts.login and accounts.getJWT. You get the needed gigyaPersonID already on login.

db-EV commented 3 years ago

And it was not the case for pyze either, there are other scripts, apps and so on with faulty Gigya integration.

kozmoz commented 3 years ago

So what's the fix to have pyze working again? Obviously some people digged into the problem.

yannickh commented 3 years ago

In the Gigya calls (getAccountInfo and getJWT), the parameter "oauth_token" should be changed to "login_token".

epenet commented 3 years ago

So what's the fix to have pyze working again? Obviously some people digged into the problem.

@kozmoz you don't describe your problem so it might not be linked to this discussion

In the Gigya calls (getAccountInfo and getJWT), the parameter "oauth_token" should be changed to "login_token".

@yannickh it is already the case in pyze since #79 was merged last year

kozmoz commented 3 years ago

So what's the fix to have pyze working again? Obviously some people digged into the problem.

@kozmoz you don't describe your problem so it might not be linked to this discussion

Exactly the same error as @timmchugh11 who started this issue.

Error communicating with Renault API! {"error":"access_denied","error_description":"Unauthorized"}

premultiply commented 3 years ago

You need to update the Kamereon API key!!!

kozmoz commented 3 years ago

Alright. Missed the new key for Kamereon, but did update the Gigya API key. In summary, this fixed my issue:

export KAMEREON_API_KEY="Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2"
export GIGYA_API_KEY="3_e8d4g4SE_Fo8ahyHwwP7ohLGZ79HKNN2T8NjQqoNnk6Epj6ilyYwKdHUyCw3wuxz"
brusch commented 3 years ago

I'm still facing issues:

Traceback (most recent call last):
  File "/opt/bin/pyze", line 8, in <module>
    sys.exit(main())
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/cli/__main__.py", line 69, in main
    parsed_args.func(parsed_args)
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/cli/status.py", line 35, in run
    v = get_vehicle(parsed_args)
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/cli/common.py", line 24, in get_vehicle
    vehicles = k.get_vehicles().get('vehicleLinks')
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/api/credentials.py", line 26, in inner
    return func(*args, **kwargs)
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/api/kamereon.py", line 114, in get_vehicles
    self.get_account_id(),
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/api/kamereon.py", line 73, in get_account_id
    accounts = self.get_accounts()
  File "/volume1/Share/Web/SmartHome/.local/lib/python3.8/site-packages/pyze/api/credentials.py", line 25, in inner
    raise MissingCredentialException(name)
pyze.api.credentials.MissingCredentialException: gigya-person-id

any ideas?

Podariss commented 3 years ago

Same here; pi@TestPi:~/pyze$ pyze status --km

Traceback (most recent call last): File "/usr/local/bin/pyze", line 11, in load_entry_point('PyZE==0.5.0', 'console_scripts', 'pyze')() File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/cli/main.py", line 69, in main File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/cli/status.py", line 35, in run File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/cli/common.py", line 24, in get_vehicle File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/api/credentials.py", line 26, in inner File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/api/kamereon.py", line 119, in get_vehicles File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/api/credentials.py", line 26, in inner File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/api/gigya.py", line 109, in get_jwt_token File "/usr/local/lib/python3.5/dist-packages/PyZE-0.5.0-py3.5.egg/pyze/api/gigya.py", line 126, in raise_gigya_errors RuntimeError: Gigya returned error 403007: Invalid namespace 'accounts' or method 'getJWT' or you do not have the required permissions to call it.

Used the mentioned api keys from above and from keys mentioned in the readme files

db-EV commented 3 years ago

Are you using the correct Gigya API keys for your country? These are different for each country. Only the Kamereon API key is static for all countries.

Podariss commented 3 years ago

I used the GB version before, but even with nl_NL no change...

berti2911 commented 3 years ago

Hi, i had the same issue and now it workes with the keys of kozmos. Then i played a bit with the keys. Here are my results: the Gigya-key is not so strikt, for me also the english and the german version worked: English

    "gigyaProd": {
        "target": "https://accounts.eu1.gigya.com",
        "apikey": "3_e8d4g4SE_Fo8ahyHwwP7ohLGZ79HKNN2T8NjQqoNnk6Epj6ilyYwKdHUyCw3wuxz"

German

    "gigyaProd": {
        "target": "https://accounts.eu1.gigya.com",
        "apikey": "3_7PLksOyBRkHv126x5WhHb-5pqC1qFR8pQjxSeLB6nhAnPERTUlwnYoznHSxwX668"

but the Kamereon Key is bitchy: neither the german nor the english version was successfull. Here i got the error message:

"Error communicating with Renault API! {"error":"access_denied","error_description":"Unauthorized"}"

Only the Kammereon key of kozmos worked. So a question to him: how did you get this key?

epenet commented 3 years ago

Key retrieval has changed on the Renault side. It is now hidden deep inside Firebase, and for now you need to use Fiddler to extract it.

There is a discussion on https://github.com/hacf-fr/renault-api/pull/184

berti2911 commented 3 years ago

@Podariss, @brusch: maybe it helps to delete first the lokal file .credentials/pyze.json before starting again with pyze login?

kozmoz commented 3 years ago

Only the Kammereon key of kozmos worked. So a question to him: how did you get this key?

In the third message of this thread. Initially I also missed that one, but later I realised that was the fix for access_denied.

https://github.com/jamesremuscat/pyze/issues/95#issuecomment-772813562

heckmic commented 3 years ago

Same Problem here:

Traceback (most recent call last): File "/usr/local/bin/pyze", line 11, in <module> load_entry_point('PyZE==0.5.0', 'console_scripts', 'pyze')() File "/usr/local/lib/python3.7/dist-packages/PyZE-0.5.0-py3.7.egg/pyze/cli/__main__.py", line 69, in main File "/usr/local/lib/python3.7/dist-packages/PyZE-0.5.0-py3.7.egg/pyze/cli/status.py", line 35, in run File "/usr/local/lib/python3.7/dist-packages/PyZE-0.5.0-py3.7.egg/pyze/cli/common.py", line 24, in get_vehicle File "/usr/local/lib/python3.7/dist-packages/PyZE-0.5.0-py3.7.egg/pyze/api/credentials.py", line 25, in inner pyze.api.credentials.MissingCredentialException: kamereon-api-key

berti2911 commented 3 years ago

@Heckmic: Did you use exactly the following KEY? Only this one worked for me. export KAMEREON_API_KEY="Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2"

And of course you have to login again: pyze login

jumpjack commented 2 years ago

I am using the updated key Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2 , but I am still getting this error:

{"type":"FUNCTIONAL","messages":[{"code":"err.func.wired.unauthorized","message":"The access is unauthorized"}],"errors":[{"errorCode":"err.func.wired.unauthorized","errorMessage":"The access is unauthorized"}],"error_reference":"FUNCTIONAL"}

I am using both direct url call and GET/POST using a Rest API Chrome extension, no luck.

My direct link: https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/persons/MY_PERSON_ID?apikey=Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2&x-gigya-id_token=MY_JWT_TOKEN&country=IT

jumpjack commented 2 years ago

I also know that there is a direct link which gives a very long JSON response, containing a lot of data, including my VIN.... but I found it by chance after dozens of attempts and I cannot get it anymore, any idea how it could be formed?

berti2911 commented 2 years ago

Are you using pyze? If not maybe you could download this library and look in the code how the web-service or link is formed. For pyze it is essential to delete first the file .credentials/pyze.json and then login again with "pyze login" to avoid old chaching.

jumpjack commented 2 years ago

Indeed I am reverse-engineering pyze and other scripts to figure out which are the direct calls to perform, to implement them in Javascript, but I am stuck at Kamereon authentication (Gigya part is fine).

fungus75 commented 2 years ago

Have a look at that: https://github.com/fungus75/ioBroker.zoe2/blob/master/main.js Rewritten pyze (and some more projects) in Javascript for usage within iobroker. Maybe it helps?

jumpjack commented 2 years ago

This is what I discovered till now:

Download api keys GIGYA_KEY and KAMEREON_KEY:

https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_it_IT.json

Download Gigya session cookie (cookieValue):

https://accounts.eu1.gigya.com/accounts.login?loginID=MAIL&password=PASSWORD&apikey=GIGYA_KEY

Download Kamereon Person Id (PersonId):

https://accounts.eu1.gigya.com/accounts.getAccountInfo?apikey=GIGYA_KEY&login_token=COOKIEVALUE

Download Gigya JWT token (Id_token):

https://accounts.eu1.gigya.com/accounts.getJWT?apikey=GIGYA_KEY&login_token=COOKIEVALUE

Then query Kamereon server in some way which I don't understand yet...

To get the account(s) associated to a personId:

https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/persons/PERSONID?country=IT

To get vehicles associated to an account:

https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/ACCOUNTID/kamereon/kca/car-adapter/v1/cars/VEHICLE_VIN/location?country=IT

AllanPetersenDK commented 1 year ago

LoginID and password for GIGYA is My renault app login? When trying to do the Download Kamereon Person Id (PersonId) i get this error. { "errorDetails": "Unauthorized user", "errorMessage": "Unauthorized user", "apiVersion": 2, "statusCode": 403, "statusReason": "Forbidden", "time": "2023-04-22T06:40:45.003Z" }

jumpjack commented 1 year ago

I think the APi key has just changed again, breaking all the custom apps.

jumpjack commented 1 year ago

This should be the new kamereon api key:

YjkKtHmGfaceeuExUDKGxrLZGGvtVS0J

Source: https://gist.github.com/mountbatt/772e4512089802a2aa2622058dd1ded7