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

400 Error: PSA status API seems to have changed? #678

Closed
slash909uk opened this issue Nov 24, 2023 · 28 comments · Fixed by #679
Closed

400 Error: PSA status API seems to have changed? #678

slash909uk opened this issue Nov 24, 2023 · 28 comments · Fixed by #679

Comments

@slash909uk
Copy link

400 HTTP Error when requesting vehicle status

as of (23/11/23)

To Reproduce
simply start program and if required call local endpoint http://localhost:5000/get_vehicleinfo/ to provoke status API call to PSA, or wait until program does it by itself...

Log output to console shows this: ( I have enabled HTTP debugging in urllib3 in addition to your application debugging, so you can see exactly what happens on the wire).
Note the 400 response payload indicates something to do with a Header error. (in bold below):

2023-11-24 09:50:08,107 DEBUG Starting new HTTPS connection (1): api.groupe-psa.com:443
2023-11-24 09:50:08,107 :: DEBUG :: Starting new HTTPS connection (1): api.groupe-psa.com:443
send: b'GET /connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e/status?extension=odometer&client_id=122f3511-4f74-4a0c-bcda-af2f3b2e3a65 HTTP/1.1\r\nHost: api.groupe-psa.com\r\nAccept-Encoding: identity\r\nAccept: application/hal+json\r\nUser-Agent: Swagger-Codegen/4.0/python\r\nAuthorization: Bearer <removed*>\r\nx-introspect-realm: clientsB2CVauxhall\r\nContent-Type: application/json\r\n\r\n'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Connection: close
header: Date: Fri, 24 Nov 2023 09:50:07 GMT
header: Expires: 0
header: Cache-Control: no-store, no-cache, must-revalidate, private
header: Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 23-Nov-2023 09:50:07 GMT
header: Set-Cookie: JSESSIONID=Kv440m8cC1gwo0yaUoqbH1Q9ASwE7e0aTAOAfVhc; path=/
header: Strict-Transport-Security: max-age=15724800; includeSubDomains
header: Content-Type: application/hal+json
header: X-Global-Transaction-ID: 32486679656071cfda9a6a3f
header: User-Agent: Swagger-Codegen/4.0/python
header: Set-Cookie: PSACountry=GB; Domain=.groupe-psa.com; Path=/
2023-11-24 09:50:08,796 DEBUG https://api.groupe-psa.com:443 "GET /connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e/status?extension=odometer&client_id=122f3511-4f74-4a0c-bcda-af2f3b2e3a65 HTTP/1.1" 400 None
2023-11-24 09:50:08,796 :: DEBUG :: https://api.groupe-psa.com:443 "GET /connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e/status?extension=odometer&client_id=122f3511-4f74-4a0c-bcda-af2f3b2e3a65 HTTP/1.1" 400 None
2023-11-24 09:50:08,808 :: DEBUG :: response body: {"uuid":"35bb70e9-ff95-412a-bb7a-bbd287523323","code":40000,"message":" Invalid parameter: X-MPHSource","timestamp":"2023-11-24T09:50:07.941Z"}
2023-11-24 09:50:08,810 :: ERROR :: get_vehicle_info: ApiException: (400)
Reason: Bad Request

Environment (please complete the following information):

  • OS: Windows
  • Brand and model of car: Vauxhall Corsa-e
  • Application version (commit number, branch or tag): PSACC 3.0.12

Possible Solution
Problem is resolved by removing [extension=odometer] query string property.

I have tested [with curl] the same API call without this parameter; it works successfully and odometer object appears to still be included in the response:

curl -v -k --header "Authorization: Bearer <removed>" --header "Host: api.groupe-psa.com" --header "x-introspect-realm: clientsB2CVauxhall" --header "Content-Type: application/json" --header "Accept: application/hal+json" --header "Accept-Encoding: identity" --get "https://api.groupe-psa.com/connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e/status?client_id=122f3511-4f74-4a0c-bcda-af2f3b2e3a65"
< HTTP/1.1 200 OK
< Connection: close
< Date: Fri, 24 Nov 2023 10:11:50 GMT
< Expires: 0
< Cache-Control: no-store, no-cache, must-revalidate, private
< Set-Cookie: rememberMe=deleteMe; Path=/; Max-Age=0; Expires=Thu, 23-Nov-2023 10:11:50 GMT
< Set-Cookie: JSESSIONID=h7Yjbi8bexWqtQzc2j6zXF_b9twnqnWCq452p__T; path=/
< Strict-Transport-Security: max-age=15724800; includeSubDomains
< Content-Type: application/hal+json
< X-Global-Transaction-ID: 08f333a5656076e60298c23f
< User-Agent: curl/7.54.0
< Set-Cookie: PSACountry=GB; Domain=.groupe-psa.com; Path=/
<
(formatted for readability)
{
"createdAt": "2023-11-24T09:44:47Z",
"updatedAt": "2023-11-24T09:44:47Z",
"ignition": {
"createdAt": "2023-11-24T09:44:47Z",
"type": "Stop"
},
"battery": {
"voltage": 71.5,
"createdAt": "2023-11-24T09:44:47Z"
},
"privacy": {
"createdAt": "2023-11-24T09:44:47Z",
"state": "None"
},
"service": {
"createdAt": "2023-10-20T19:43:00Z",
"type": "Electric"
},
"environment": {
"luminosity": {
"createdAt": "2023-11-24T09:44:47Z",
"day": true
},
"air": {
"createdAt": "2023-11-24T09:44:47Z",
"temp": 8.5
}
},
"odometer": {
"createdAt": "2023-11-24T09:44:47Z",
"mileage": 6218.1
},

"_links": {
"self": {
"href": "https://api.groupe-psa.com/connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e/status?profile=endUser"
},
"vehicle": {
"href": "https://api.groupe-psa.com/connectedcar/v4/user/vehicles/1c8bedfe1bd229d9cf0fee6613462af127a77c0a3ca67b4cad3399856d40cad6f7e13d53f4930922a8159da20f738a579e576284871a4ddb840f3d72016cfad9248617be0f502e8de8b47c0ef511388e72acafd3bd348b2f0220e2956f14fe25e"
}
},
"preconditioning": {
"airConditioning": {
"createdAt": "2023-11-24T09:44:47Z",
"updatedAt": "2023-11-24T09:44:47Z",
"status": "Disabled",
"programs": [
{
"enabled": false,
"slot": 1,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 2,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 3,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 4,
"recurrence": "Daily",
"start": "PT0S"
}
]
}
},
"energies": [
{
"createdAt": "2023-11-24T09:44:47Z",
"type": "Electric",
"subType": "ElectricEnergy",
"level": 76,
"autonomy": 260,
"extension": {
"electric": {
"battery": {
"load": {
"createdAt": "2023-11-24T09:44:47Z",
"capacity": 36640,
"residual": 26304
}
},
"charging": {
"plugged": false,
"status": "Disconnected",
"chargingRate": 0,
"chargingMode": "No",
"nextDelayedTime": "PT30M"
}
}
}
}
],
"preconditionning": {
"airConditioning": {
"createdAt": "2023-11-24T09:44:47Z",
"updatedAt": "2023-11-24T09:44:47Z",
"status": "Disabled",
"programs": [
{
"enabled": false,
"slot": 1,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 2,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 3,
"recurrence": "Daily",
"start": "PT0S"
},
{
"enabled": false,
"slot": 4,
"recurrence": "Daily",
"start": "PT0S"
}
]
}
},
"energy": [
{
"createdAt": "2023-11-24T09:44:47Z",
"updatedAt": "2023-11-24T09:44:47Z",
"type": "Electric",
"level": 76,
"autonomy": 260,
"charging": {
"plugged": false,
"status": "Disconnected",
"chargingRate": 0,
"chargingMode": "No",
"nextDelayedTime": "PT30M"
}
}
]
}

@Reddax
Copy link

Reddax commented Nov 24, 2023

Yeah i'm getting the same :( Suddenly stopped working yesterday afternoon

@MaxenceRemy
Copy link

Thanks, this seems to solve the problem indeed. I don't know if this could be a long term fix but at least you are onto something !

mdkeil added a commit to mdkeil/psa_car_controller that referenced this issue Nov 24, 2023
@sod75
Copy link

sod75 commented Nov 24, 2023

Same issue here

@Kondors1
Copy link

Is this solution?
What exactly should I do to resolve this?

@HenningS81
Copy link
Contributor

Thanks for your investigation into this issue.
Stupid question: where can I start to modify the docker container to get it going again? Is there a manual for that?

@GewoonJaap
Copy link
Contributor

Getting the same error here since last night (e-208) :(
Hopefully we can get it fixed :D

@GewoonJaap
Copy link
Contributor

GewoonJaap commented Nov 24, 2023

Thanks for your investigation into this issue. Stupid question: where can I start to modify the docker container to get it going again? Is there a manual for that?

You can manually edit the file in your docker container, wait until this docker gets updated or use my fork:
https://github.com/GewoonJaap/psa_car_controller/
It has a few new API endpoints (2.12/2.13) aswell :)
Will soon open a PR here to merge those changes in the base image

@sod75
Copy link

sod75 commented Nov 24, 2023

the long term solution is to incorporate @mdkeil 's PR and release a new version that everyone can update to.

Short term AND TEMPORARY for those running docker
log on to the command line of where it's running and do the following

#Get the ID of the running image

$ docker ps | grep flobz
**ae533ea8432f**   flobz/psa_car_controller:latest         "/bin/sh -c /init.sh"    8 days ago      Up 7 minutes           0.0.0.0:3000->3000/tcp   

#open a shell into the running container

$ docker exec -it ae533ea8432f bash
root@ae533ea8432f:/config#

#change to the correct folder
root@ae533ea8432f:/config# cd /usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/

#install your file editor of choice

root@ae533ea8432f:/app# apt-get update
root@ae533ea8432f:/app# apt-get -y install vim

#edit line 105 of psa_client.py from
root@ae533ea8432f:/app#vi psa_client.py
from
res = self.api().get_vehicle_status(car.vehicle_id, extension=["odometer"])
to
res = self.api().get_vehicle_status(car.vehicle_id)

#save and restart the container

This will all be deleted if you do an update, etc

@HenningS81
Copy link
Contributor

Thank you so much @sod75 and @GewoonJaap !
It works again.

@slash909uk
Copy link
Author

Thanks for quick patch guys 👍

@JaySea77
Copy link

It has a few new API endpoints (2.12/2.13) aswell :)

You also have a couple other endpoints like unlock and horn that aren't in this one

@GewoonJaap
Copy link
Contributor

Yup, those are included as well :)

@Kondors1
Copy link

Is there any manual how to resolve this for dummies like me?

@Reddax
Copy link

Reddax commented Nov 24, 2023

Is there any manual how to resolve this for dummies like me?

sod75 did a good tutorial above if you're running it in docker

@nosuchuser
Copy link

nosuchuser commented Nov 24, 2023


#edit line 105 of psa_client.py from `root@ae533ea8432f:/app#vi psa_client.py` from ` res = self.api().get_vehicle_status(car.vehicle_id, extension=["odometer"])` to ` res = self.api().get_vehicle_status(car.vehicle_id)`

#save and restart the container

I found out that doing this might not actually work on all scenarios. I had to delete the matching .pyc file before restarting the container to have things running back as before

Run find / -name psa_client*.pyc inside the container and remove the file

In my case it was:
/usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/pycache/psa_client.cpython-39.pyc

@nicknol
Copy link

nicknol commented Nov 24, 2023

Unfortunately, I need your help. I applied the change to psa_client.py as described.
But after a restart of the container psa_client.py looks as before.

I removed as well the file in the __pychache.
But after a restart of the container psa_client.py looks as before.

any hint?

@nosuchuser
Copy link

Did you reboot from within the container? That happened to me when I tried it that way.

You have to edit the .py file, remove the .pyc file, exit the shell and do “docker restart” on the container. Then open a new shell and check if the changes remain (the pyc file is generated when you access the app webpage)

@mdkeil
Copy link
Contributor

mdkeil commented Nov 24, 2023

the change don't survive a container reboot. You can create a bind mount from /host/mnt/psa_client.py (modified version) to /usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py

@nicknol
Copy link

nicknol commented Nov 24, 2023

@mdkeil thanks for the fast response and hints.
I didn't find /host/mnt/
There is only /mnt
I created a link
ln mnt/psa_client.py /usr/local/lib/python3.9/dist-packages/psa_car_controller/psacc/application/psa_client.py
for the modified version in /mnt
After a reboot the new version and the links are gone again.

you see, I don't have many clues on docker ...

@mdkeil
Copy link
Contributor

mdkeil commented Nov 24, 2023

/host/mnt is a wildcard for an any folder at the host system 😉

https://docs.docker.com/storage/bind-mounts/

@sanzoghenzo
Copy link

FYI, instead of offering a stable API, stellantis explicitly states that one needs to keep up with the changes 😠

Be careful, this API is very likely to have updates in the future, that’s why your application has to support evolution regarding the schema of exposed data.

In order to ensure the API backward compatibility with previous versions, we pledge to keep the same unit for each field in a JSON response body.

However, it’s possible that we choose to add a new field in a JSON response body. Your application should then handle dealing with unknown properties.

Furthermore, regarding the nature of this API, it could append that some fields are missing in the JSON response body. In this case, your application should be able to manage with the absence of the field and not cause an error.

@martynhr
Copy link

Thanks for your investigation into this issue. Stupid question: where can I start to modify the docker container to get it going again? Is there a manual for that?

You can manually edit the file in your docker container, wait until this docker gets updated or use my fork: https://github.com/GewoonJaap/psa_car_controller/ It has a few new API endpoints (2.12/2.13) aswell :) Will soon open a PR here to merge those changes in the base image

Ok so I've Home assistant OS with no access to SSH (have never configured it). How do I update to this version to get it all working again??

@JaySea77
Copy link

FYI, instead of offering a stable API, stellantis explicitly states that one needs to keep up with the changes 😠

That is not what happened here. The API cannot handle an extra field in the request. So the API is not as flexible as they expect the users to be

flobz pushed a commit that referenced this issue Nov 25, 2023
@JaySea77
Copy link

JaySea77 commented Nov 25, 2023

When I edit the file and restart the container. The change is gone. I also cannot use vi anymore and have to do the apt-get update etc again.
How can I restart the container without losing the changes?
Ps I am using the home assistant addon which is not updated yet.

Edit: exit the container and doing docker restart worked!

@RiderCrazy
Copy link

When I edit the file and restart the container. The change is gone. I also cannot use vi anymore and have to do the apt-get update etc again. How can I restart the container without losing the changes? Ps I am using the home assistant addon which is not updated yet.

Don't use restart from HA. When you have finished, just leave the docker instance (ctrl + d) and then use command
docker restart #idOfPsaDocker

@Doser86
Copy link

Doser86 commented Jan 26, 2024

I have HA OS. How can I fix this?

@Rupes7
Copy link

Rupes7 commented Jan 27, 2024

Same issue here - how can I fix this in HA OS?

@Xrlwyzz
Copy link

Xrlwyzz commented Feb 10, 2024

In HA OS it is difficult. You can try the solution posted in the last comment here:
https://community.home-assistant.io/t/access-addons-data/428429/4

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

Successfully merging a pull request may close this issue.