CJNE / pyporscheconnectapi

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

Cannot connect to host my.porsche.com:443 #14

Closed sracing closed 1 year ago

sracing commented 2 years ago

I am using pyporscheconnectapi since a few month in a smarthome application (SmarthomeNG). So far, everything worked well and I pulled fresh data every 10 minutes. Since a few days, I am experiencing more and more connection issues.

My script to test the connection:

import asyncio
from pyporscheconnectapi.connection import Connection

email = "my@adress.de"
password = "mypassword"

async def vehicles():
    conn = Connection(email, password)

    data = await conn.get("https://api.porsche.com/service-vehicle/se/sv_SE/vehicle-data/WP0ZZZxxxxxxxxxxxxx/stored")

    await conn.close()
    return data

loop = asyncio.get_event_loop()
result = loop.run_until_complete(vehicles())

print(result)

The error message:

Traceback (most recent call last):
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1025, in create_connection
    raise exceptions[0]
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 1010, in create_connection
    sock = await self._connect_sock(
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 924, in _connect_sock
    await self.sock_connect(sock, address)
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 702, in sock_connect
    return await self._proactor.connect(sock, address)
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\windows_events.py", line 812, in _poll
    value = callback(transferred, key, ov)
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\windows_events.py", line 599, in finish_connect
    ov.getresult()
OSError: [WinError 121] Das Zeitlimit für die Semaphore wurde erreicht

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:/Users/Marcus/AppData/Roaming/JetBrains/PyCharmCE2022.1/scratches/example2.py", line 38, in <module>
    result = loop.run_until_complete(vehicles())
  File "C:\Users\Marcus\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "C:/Users/Marcus/AppData/Roaming/JetBrains/PyCharmCE2022.1/scratches/example2.py", line 25, in vehicles
    data = await conn.get("https://api.porsche.com/service-vehicle/se/sv_SE/vehicle-data/WP0ZZZxxxxxxxxxxxx/stored")
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\pyporscheconnectapi\connection.py", line 181, in get
    headers = await self._createhead(application)
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\pyporscheconnectapi\connection.py", line 229, in _createhead
    token = await self._requestToken(application, wasExpired=(token is not None))
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\pyporscheconnectapi\connection.py", line 127, in _requestToken
    await self._login()
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\pyporscheconnectapi\connection.py", line 102, in _login
    async with self.websession.post(self.porscheLoginAuth,  data=login_data, max_redirects=30) as resp:
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\client.py", line 535, in _request
    conn = await self._connector.connect(
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "C:\Users\Marcus\PycharmProjects\pyReoCtrl\venv\lib\site-packages\aiohttp\connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host my.porsche.com:443 ssl:default [Das Zeitlimit für die Semaphore wurde erreicht]
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x0000029BDD30C700>

As said, I believe the issue did not come up instantly, I more had the impreesion it came up more and more over the last days. Now approx. 95% of the connections fail.

Is it just me having those issues? Anything I can do in my script to solve this?

Any support or feedback is appreciated.

sracing commented 1 year ago

Since 2022-07-01 // 03:00 am there is stable connection again without having changed anything on my side. Seems the root cause was on the Porsche Server side for several days.