CJNE / pyporscheconnectapi

Python client library for Porsche Connect API
MIT License
44 stars 9 forks source link

Error while trying to get "getEmobility" conn {'pcckErrorKey': 'GRAY_SLICE_ERROR_UNKNOWN_MSG', 'pcckErrorMessage': None, 'pcckErrorCode': None, 'pcckIsBusinessError': True} #39

Closed TimoD87 closed 7 months ago

TimoD87 commented 7 months ago

When I'm trying to get Information with client.getEmobility(vin, model) i get the following error:

conn {'pcckErrorKey': 'GRAY_SLICE_ERROR_UNKNOWN_MSG', 'pcckErrorMessage': None, 'pcckErrorCode': None, 'pcckIsBusinessError': True}

Trying to get the data direct with the cli.py the data looks okay:

{ "batteryChargeStatus": { "plugState": "DISCONNECTED", "lockState": "UNLOCKED", "chargingState": "OFF", "chargingReason": "INVALID", "externalPowerSupplyState": "UNAVAILABLE", "ledColor": "NONE", "ledState": "OFF", "chargingMode": "OFF", "stateOfChargeInPercentage": 70, "remainingChargeTimeUntil100PercentInMinutes": null, "remainingERange": { "value": 301, "unit": "KILOMETERS", "originalValue": 301, "originalUnit": "KILOMETERS", "valueInKilometers": 301, "unitTranslationKey": "GRAY_SLICE_UNIT_KILOMETER", "unitTranslationKeyV2": "TC.UNIT.KILOMETER" }, "remainingCRange": null, "chargingTargetDateTime": "2023-11-14T05:33", "status": null, "chargeRate": { "value": 0, "unit": "KM_PER_MIN", "valueInKmPerHour": 0, "unitTranslationKey": "EM.COMMON.UNIT.KM_PER_MIN", "unitTranslationKeyV2": "TC.UNIT.KM_PER_MIN" }, "chargingPower": 0, "chargingTargetDateTimeOplEnforced": null, "chargingInDCMode": false }, "directCharge": { "disabled": true, "isActive": false }, "directClimatisation": { "climatisationState": "OFF", "remainingClimatisationTime": null, "targetTemperature": "2950", "climatisationWithoutHVpower": "false", "heaterSource": "electric" }, "timers": [ { "timerID": "1", "departureDateTime": "2023-11-17T13:31:00.000Z", "preferredChargingTimeEnabled": false, "preferredChargingStartTime": null, "preferredChargingEndTime": null, "frequency": "SINGLE", "climatised": true, "weekDays": null, "active": false, "chargeOption": true, "targetChargeLevel": 25, "climatisationTimer": false, "e3_CLIMATISATION_TIMER_ID": "4" } ], "climateTimer": null, "chargingProfiles": { "currentProfileId": 0, "profiles": [ { "profileId": 4, "profileName": "Allgemein", "profileActive": false, "profileOptions": { "autoPlugUnlockEnabled": false, "energyCostOptimisationEnabled": false, "energyMixOptimisationEnabled": false, "powerLimitationEnabled": false, "timeBasedEnabled": false, "usePrivateCurrentEnabled": true }, "chargingOptions": { "minimumChargeLevel": 25, "targetChargeLevel": 100, "smartChargingEnabled": true, "preferredChargingEnabled": false, "preferredChargingTimeStart": "00:00", "preferredChargingTimeEnd": "06:00" }, "position": null, "timerActionList": { "timerAction": [ 1, 2, 3, 4, 5 ] } } ] }, "departureInformation": null, "errorInfo": []

Don't know were the error is coming from :-(

augmentedtraffic commented 7 months ago

I started getting some errors a few hours ago but not the same as you when using CLI - I get the following

Note in the past sometimes wait for a few hours (24) and it may start working again. I think I have seen this before and something got reset after a period of time. I was debugging this morning so issued a few API calls in quite a short period of time (which may trigger something)

Traceback (most recent call last): File "./c.py", line 4, in cli() File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/cli.py", line 270, in cli loop.run_until_complete(main(args)) File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete return future.result() File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/cli.py", line 47, in main data = await client.getVehicles() File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/client.py", line 449, in getVehicles f"https://api.porsche.com/core/api/v3/{self.locale_str}/vehicles" File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/connection.py", line 237, in get headers = await self._createhead(application) File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/connection.py", line 292, in _createhead application, wasExpired=(token is not None) File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/connection.py", line 206, in _requestToken await self._login() File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/connection.py", line 171, in _login resume_url = resp.headers['Location'] KeyError: 'Location' ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x734b05d0> ERROR:asyncio:Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x73544378>, 8222.623261835)]'] connector: <aiohttp.connector.TCPConnector object at 0x734b0530>

barto64 commented 7 months ago

I am getting this one after 15:00 CET:

2023-11-16 15:11:51.672 ERROR (MainThread) [custom_components.porscheconnect] Unexpected error fetching porscheconnect data: 'vehicleServiceEnabledMap' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 256, in _async_update_data vdata = await self._update_data_for_vehicle(vehicle) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/porscheconnect/init.py", line 146, in _update_data_for_vehicle services = await self.controller.getServices(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pyporscheconnectapi/client.py", line 488, in getServices is_privacy = data['vehicleServiceEnabledMap']['VSR'] == 'DISABLED'


KeyError: 'vehicleServiceEnabledMap'
fredriklj commented 7 months ago

I tend to think this may be due to intermittent problems in the back-end. I can see that sometime the same call fails and sometimes it gets through. Let's give it a few days before trying to chase it down further.

augmentedtraffic commented 7 months ago

OK it is working for me once again - didn't hit an API for > 12 hours. My typical cadence is about one ping an hour (other than when I am debugging)

fredriklj commented 7 months ago

I was still getting seemingly random failures, probably things are in flux as they are rolling out new functions. I may have found out that we need to set a different scope when authenticating.

If you are still experiencing problems, please try out #40 .. grateful for your feedback.

augmentedtraffic commented 7 months ago

I had one failure a couple of hours ago but retried (within 20 minutes) and it worked. I will monitor and try your update if I get back into the state of it not working again. Note sometimes when it fails I try the mobile app to ensure their APIs are actually working as it sometimes goes down for a period of time.

augmentedtraffic commented 7 months ago

OK I finally got the failures for the last 3 hours. I just tried it failed with the following errors:

Traceback (most recent call last): File "./porsche1.py", line 142, in loop.run_until_complete(vehicles()) File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete return future.result() File "./porsche1.py", line 73, in vehicles data = await client.getCurrentOverview(vin) File "/usr/local/lib/python3.7/dist-packages/pyporscheconnectapi/client.py", line 464, in getCurrentOverview f"https://api.porsche.com/service-vehicle/{self.locale_str}/vehicle-data/{vin}/current/request/{progressResult['requestId']}/status" KeyError: 'requestId' Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x732b3130> Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x73321c00>, 337271.991742553)]', '[(<aiohttp.client_proto.ResponseHandler object at 0x732c8420>, 337275.366806426)]'] connector: <aiohttp.connector.TCPConnector object at 0x732b3150>

and then I immediately tried your new patch and it works!!! I will keep using that version and see how it goes.

Thanks!

fredriklj commented 7 months ago

If you really want to bring out your daring side (and help me with some testing), you could check out the "cleanup" branch and try that. The name says it all, but also incorporates the fix with the oauth2 scope.