Open dahlb opened 2 years ago
@cdnninja and/or @speedking456 it would be great if either of you could generate some sample responses for this package as Canadian Dev :)
I'm getting a wrong signature type error, see below.
aiohttp.client_exceptions.ClientConnectorSSLError: Cannot connect to host kiaconnect.ca:443 ssl:default [[SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:997)]
based on https://stackoverflow.com/questions/63347818/aiohttp-client-exceptions-clientconnectorerror-cannot-connect-to-host-stackover it looks like an issue caused by your development environment.
give this version a try please.
import logging
import asyncio
from aiohttp import ClientSession
from kia_hyundai_api import CaKia
logger = logging.getLogger("kia_hyundai_api.ca")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
import asyncio
async def testing():
client_session = ClientSession(raise_for_status=True, trust_env=True)
ca = CaKia(client_session=client_session)
pin = "PIN"
login_response = await ca.login("user", "pass")
access_token = login_response["access_token"]
vehicles = await ca.get_vehicles(access_token)
vehicle_id = vehicles["vehicles"][0]["vehicleId"]
await ca.get_cached_vehicle_status(access_token=access_token, vehicle_id=vehicle_id)
await ca.get_next_service_status(access_token=access_token, vehicle_id=vehicle_id)
pin_token = await ca.get_pin_token(access_token=access_token, pin=pin)
await ca.get_location(access_token=access_token, vehicle_id=vehicle_id, pin=pin, pin_token=pin_token)
asyncio.run(testing())
Still have the same issue, I've run it on all my different development environments, MacOS, Windows, and Ubuntu and still get the same error.
@speedking456 after further investigation I have a few things for you to try, simplest is this updated code that might work on your existing development environments.
import logging
import asyncio
from aiohttp import ClientSession, TCPConnector
from kia_hyundai_api import CaKia
logger = logging.getLogger("kia_hyundai_api.ca")
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
import asyncio
async def testing():
client_session = ClientSession(raise_for_status=True, trust_env=True, connector=TCPConnector(ssl=False, verify_ssl=False))
ca = CaKia(client_session=client_session)
pin = "PIN"
login_response = await ca.login("user", "pass")
access_token = login_response["access_token"]
vehicles = await ca.get_vehicles(access_token)
vehicle_id = vehicles["vehicles"][0]["vehicleId"]
await ca.get_cached_vehicle_status(access_token=access_token, vehicle_id=vehicle_id)
await ca.get_next_service_status(access_token=access_token, vehicle_id=vehicle_id)
pin_token = await ca.get_pin_token(access_token=access_token, pin=pin)
await ca.get_location(access_token=access_token, vehicle_id=vehicle_id, pin=pin, pin_token=pin_token)
asyncio.run(testing())
if that works these steps could fix your local environments for ssl use.
for MacOS (adjusted for your version number)
/System/Volumes/Data/Applications/Python 3.8/Install Certificates.command
for Windows
python -m pip install python-certifi-win32
for ubuntu
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
I've already run install certificates before, but I did it again for posterity, still get the same error if I remove verify_ssl=false
. However, the code you provided gives a different error, see below:
/Users/speedking456/Library/Application Support/JetBrains/PyCharmCE2021.3/scratches/scratch.py:14: DeprecationWarning: verify_ssl is deprecated, use ssl=False instead
client_session = ClientSession(raise_for_status=True, trust_env=True, connector=TCPConnector(ssl=False, verify_ssl=False))
Traceback (most recent call last):
File "/Users/speedking456/Library/Application Support/JetBrains/PyCharmCE2021.3/scratches/scratch.py", line 26, in <module>
asyncio.run(testing())
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
return future.result()
File "/Users/speedking456/Library/Application Support/JetBrains/PyCharmCE2021.3/scratches/scratch.py", line 14, in testing
client_session = ClientSession(raise_for_status=True, trust_env=True, connector=TCPConnector(ssl=False, verify_ssl=False))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/connector.py", line 780, in __init__
self._ssl = _merge_ssl_params(ssl, verify_ssl, ssl_context, fingerprint)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 159, in _merge_ssl_params
raise ValueError(
ValueError: verify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusive
I'm curious what version of python you are running. I'll switch versions to whatever you are running and try that.
@speedking456 sorry about the extra parameter, I saw somewhere that verify_ssl=False is deprecated but I'd never see the newer version before so I thought to try both, didn't expect them to be mutually exclusive. The original research result would suggest that your error is from using ssl over a proxy, that's what the trust_env=True is supposed to fix. I have more often see bad cert issues which should have returned a slightly different error but seemed worth trying anyway.
This is what I get when I run the initial code in this thread
dahlb@Brendans-MBP kia_hyundai_api % python3
Python 3.9.8 (main, Nov 10 2021, 09:21:22)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> import asyncio
>>> from kia_hyundai_api import CaKia
>>> logger = logging.getLogger("kia_hyundai_api.ca")
>>> logger.setLevel(logging.DEBUG)
>>> ch = logging.StreamHandler()
>>> ch.setLevel(logging.DEBUG)
>>> formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
>>> ch.setFormatter(formatter)
>>> logger.addHandler(ch)
>>> import asyncio
>>> async def testing():
... ca = CaKia()
... pin = "PIN"
... login_response = await ca.login("user", "pass")
... access_token = login_response["access_token"]
... vehicles = await ca.get_vehicles(access_token)
... vehicle_id = vehicles["vehicles"][0]["vehicleId"]
... await ca.get_cached_vehicle_status(access_token=access_token, vehicle_id=vehicle_id)
... await ca.get_next_service_status(access_token=access_token, vehicle_id=vehicle_id)
... pin_token = await ca.get_pin_token(access_token=access_token, pin=pin)
... await ca.get_location(access_token=access_token, vehicle_id=vehicle_id, pin=pin, pin_token=pin_token)
...
>>> asyncio.run(testing())
2021-12-24 20:05:44,961 - kia_hyundai_api.ca - DEBUG - sending https://kiaconnect.ca/tods/api/lgn request with {'loginId': 'user', 'password': 'pass'}
2021-12-24 20:05:46,075 - kia_hyundai_api.ca - DEBUG - response headers:<CIMultiDictProxy('Date': 'Sat, 25 Dec 2021 01:05:45 GMT', 'Server': 'Oracle-Application-Server-11g', 'Access-Control-Allow-Methods': 'POST, GET', 'Access-Control-Max-Age': '1000', 'Access-Control-Allow-Headers': 'language, offset, UCID, From, x-requested-with, Content-Type, origin, authorization, accept, client-security-token, accesstoken, clientId, clientSecret', 'Access-Control-Allow-Credentials': 'true', 'offset': '-8', 'Access-Control-Expose-Headers': 'transactionId, transactionDate, offset, language', 'Access-Control-Allow-Headers': 'x-requested-with', 'transactionId': '709672891', 'transactionDate': 'Sat, 25 Dec 2021 01:05:46 GMT', 'Set-Cookie': 'dtCookie=v_4_srv_1_sn_AD7B55187D6D5677B57618641F56D8C4_perc_100000_ol_0_mul_1_app-3Aea7c4b59f27d43eb_0; Path=/; Domain=.kiaconnect.ca', 'Access-Control-Allow-Methods': 'POST, GET', 'Access-Control-Allow-Origin': '*', 'X-Powered-By': 'Servlet/2.5 JSP/2.1', 'Access-Control-Max-Age': '3600', 'language': '0', 'Server-Timing': 'dtRpid;desc="-1889339925"', 'Timing-Allow-Origin': '*', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Language': 'en')>
2021-12-24 20:05:46,075 - kia_hyundai_api.ca - DEBUG - response text:{"error":{"errorCode":"7404","errorDesc":"The login information you entered is incorrect. Multiple incorrect login attempts may result in account lock-out."},"responseHeader":{"responseCode":1,"responseDesc":"Failure"}}
2021-12-24 20:05:46,075 - kia_hyundai_api.ca - ERROR - invalid password
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/Cellar/python@3.9/3.9.8/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "<stdin>", line 4, in testing
File "/usr/local/lib/python3.9/site-packages/kia_hyundai_api/ca.py", line 132, in login
await self._post_request_with_logging_and_errors_raised(
File "/usr/local/lib/python3.9/site-packages/kia_hyundai_api/ca.py", line 43, in request_with_logging_wrapper
raise AuthError(response_json["error"]["errorDesc"])
kia_hyundai_api.errors.AuthError: The login information you entered is incorrect. Multiple incorrect login attempts may result in account lock-out.
I'm on macOS 12.0.1 using brew to setup python with these formulas installed
dahlb@Brendans-MBP kia_hyundai_api % brew list
==> Formulae
brotli ca-certificates icu4c libuv mpdecimal openssl@1.1 python@3.9 six xz
c-ares gdbm libnghttp2 mitmproxy node protobuf readline sqlite
I'm sorry, I haven't been able to help track down this error so far, I'm pretty new to python myself and am just going off what I can google about the error message.
I know you initially found this project from the HA integration it has since been released on HACS and another CA user has debugged past login at least so that might be another route to try to generate responses and maybe your HA setup won't have this ssl issue ...
I tried to get some output to post here, but resulted in an error using the test in the 1st post. The login is successful and I get a bearer token in the response, but then fails with the output below:
2023-03-28 20:27:25,062 - kia_hyundai_api.ca - DEBUG - sending https://kiaconnect.ca/tods/api/vhcllst request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib64/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "<stdin>", line 6, in testing
File "/home/bmacleod/.local/lib/python3.9/site-packages/kia_hyundai_api/ca.py", line 133, in get_vehicles
await self._post_request_with_logging_and_errors_raised(
File "/home/bmacleod/.local/lib/python3.9/site-packages/kia_hyundai_api/ca.py", line 28, in request_with_logging_wrapper
response = await func(*args, **kwargs)
File "/home/bmacleod/.local/lib/python3.9/site-packages/kia_hyundai_api/ca.py", line 109, in _post_request_with_logging_and_errors_raised
pin = json_body.get("pin")
AttributeError: 'NoneType' object has no attribute 'get'
from a python console run
but with real username, password, and PIN. the console should show all the responses raw json; if you can post the responses I'll add them to the API files for reference like I did for the us kia version https://github.com/dahlb/kia_hyundai_api/blob/master/src/kia_hyundai_api/us_kia.py#L140
BE SURE TO REMOVE ANY PII like vin, but I'm not sure which PII will be in the responses, you could email it to me at dahl.brendan@gmail.com if you want a second pair of eyes to check for PII before it's online. Feel free to add the documentation in a PR if you'd like :).