CJNE / pyporscheconnectapi

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

KeyError: 'code' - not working anymore #37

Closed TimoD87 closed 7 months ago

TimoD87 commented 7 months ago

Getting Error:

`Traceback (most recent call last): File "/home/pi/pypo-main/cli.py", line 4, in cli() File "/home/pi/pypo-main/pyporscheconnectapi/cli.py", line 270, in cli loop.run_until_complete(main(args)) File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/home/pi/pypo-main/pyporscheconnectapi/cli.py", line 67, in main data = await client.getCurrentOverview(vin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/pypo-main/pyporscheconnectapi/client.py", line 460, in getCurrentOverview progressResult = await self._connection.post( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/pypo-main/pyporscheconnectapi/connection.py", line 246, in post headers = await self._createhead(application) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/pypo-main/pyporscheconnectapi/connection.py", line 291, in _createhead token = await self._requestToken( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/pypo-main/pyporscheconnectapi/connection.py", line 206, in _requestToken await self._login() File "/home/pi/pypo-main/pyporscheconnectapi/connection.py", line 183, in _login self.auth_state["code"] = params["code"][0]


KeyError: 'code'`

Anyone a fix for this or a workaround? Maybe Polling Time Settings?
Jmi91 commented 7 months ago

Same problem for me...

MarkusGH commented 7 months ago

Try to login via web browser and solve the captcha. Also car going to privacy mode gives problems (check in porsche app).

TimoD87 commented 7 months ago

Try to login via web browser and solve the captcha. Also car going to privacy mode gives problems (check in porsche app).

Login via Web Login with Capatcha from same IP is working, error is still there - car has no privacy on

MarkusGH commented 7 months ago

Log out/in again until no captcha is shown.

fastlorenzo commented 7 months ago

Same here, if I switch IP (using VPN), no captcha is shown and this is working. We should identify what's the threshold in term of polling (which I believe is what is in place to force a captcha).

MarkusGH commented 7 months ago

Same here, if I switch IP (using VPN), no captcha is shown and this is working. We should identify what's the threshold in term of polling (which I believe is what is in place to force a captcha).

IMHO there is such an easy thing like a threshold. evcc uses also uses the Porsche API (with refresh tokens), and when my car is not polled for like 12 hours the captcha still shows the next morning.

Dual01 commented 7 months ago

Since a few days, it does not work for me either. Here is the error message: Traceback (most recent call last): File "/home/pi/.local/bin/porschecli", line 10, in sys.exit(cli()) File "/home/pi/.local/lib/python3.7/site-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 "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/cli.py", line 81, in main data = await client.getEmobility(vin, model=args.model) File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/client.py", line 534, in getEmobility data = await self.getCapabilities(vin) File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/client.py", line 494, in getCapabilities f"https://api.porsche.com/service-vehicle/vcs/capabilities/{vin}" File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/connection.py", line 237, in get headers = await self._createhead(application) File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/connection.py", line 292, in _createhead application, wasExpired=(token is not None) File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/connection.py", line 206, in _requestToken await self._login() File "/home/pi/.local/lib/python3.7/site-packages/pyporscheconnectapi/connection.py", line 183, in _login self.auth_state["code"] = params["code"][0] KeyError: 'code' ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x734c76b0> ERROR:asyncio:Unclosed connector connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x734ce068>, 5497252.017260205)]'] connector: <aiohttp.connector.TCPConnector object at 0x734c75f0>

What could be the problem? Logging in via the website works

MarkusGH commented 7 months ago

As written above a captcha is a common problem. Sometimes you have to log on/off multiple times from the same IP until no captcha is shown.

Dual01 commented 7 months ago

ah ok, got it. Thanks

Dual01 commented 7 months ago

The problem is that even after several log on/offs, it works for several hours and then I am asked again for a captcha and I get the message: keyerror: code.

fredriklj commented 7 months ago

Duplicate of #37