bimmerconnected / bimmer_connected

🚘 Library to query the status of your BMW or Mini from the ConnectedDrive portal
Apache License 2.0
362 stars 79 forks source link

HTTPStatusError: invalid_client #533

Closed olyashok closed 6 months ago

olyashok commented 1 year ago

Describe the issue

import asyncio from bimmer_connected.account import MyBMWAccount from bimmer_connected.api.regions import Regions

async def main(): account = MyBMWAccount('xxxxx', 'xxxxx', Regions.NORTH_AMERICA) await account.get_vehicles() vehicle = account.get_vehicle(VIN) print(vehicle.brand, vehicle.name, vehicle.vin)

asyncio.run(main())

MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method) Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 353, in raise_for_status_event_handler response.raise_for_status() File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status raise HTTPStatusError(message, request=request, response=self) httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://login.bmwusa.com/gcdm/oauth/authenticate' For more information check: https://httpstatuses.com/401

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

Traceback (most recent call last): File "/config/./bmw.py", line 11, in asyncio.run(main()) File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete return future.result() File "/config/./bmw.py", line 7, in main await account.get_vehicles() File "/usr/local/lib/python3.10/site-packages/bimmer_connected/account.py", line 93, in get_vehicles await self._init_vehicles() File "/usr/local/lib/python3.10/site-packages/bimmer_connected/account.py", line 72, in _init_vehicles vehicles_responses: List[httpx.Response] = [ File "/usr/local/lib/python3.10/site-packages/bimmer_connected/account.py", line 73, in await client.get( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1754, in get return await self.request( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1642, in _send_handling_auth request = await auth_flow.anext() File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 76, in async_auth_flow await self.login() File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 114, in login token_data = await self._login_row_na() File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 165, in _login_row_na response = await client.post( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1845, in post return await self.request( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1703, in _send_handling_redirects raise exc File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects await hook(response) File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 355, in raise_for_status_event_handler await handle_httpstatuserror(ex, log_handler=_LOGGER) File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/utils.py", line 75, in handle_httpstatuserror raise _ex_to_raise(_err_message) from ex bimmer_connected.models.MyBMWAuthError: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)

Expected behavior

Login

Which Home Assistant version are you using?

2023.5.2

What was the last working version of Home Assistant Core?

2023.5.2

What is your region?

North America

MyBMW website

Number of cars

Output of bimmer_connected fingerprint

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

CONSULitAS commented 1 year ago

same here with standalone binary

$ /home/pi/.local/bin/bimmerconnected status -j xx@xx.xx "xxx" rest_of_world
DEBUG:asyncio:Using selector: EpollSelector
MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/authentication.py", line 353, in raise_for_status_event_handler
    response.raise_for_status()
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_models.py", line 736, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://customer.bmwgroup.com/gcdm/oauth/authenticate'
For more information check: https://httpstatuses.com/401

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

Traceback (most recent call last):
  File "/home/pi/.local/bin/bimmerconnected", line 10, in <module>
    sys.exit(main())
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/cli.py", line 356, in main
    loop.run_until_complete(args.func(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/bimmer_connected/cli.py", line 138, in get_status
    await account.get_vehicles()
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/account.py", line 93, in get_vehicles
    await self._init_vehicles()
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/account.py", line 79, in _init_vehicles
    for brand in CarBrands
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/account.py", line 79, in <listcomp>
    for brand in CarBrands
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1760, in get
    extensions=extensions,
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1618, in send
    history=[],
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1639, in _send_handling_auth
    request = await auth_flow.__anext__()
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/authentication.py", line 76, in async_auth_flow
    await self.login()
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/authentication.py", line 114, in login
    token_data = await self._login_row_na()
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/authentication.py", line 172, in _login_row_na
    "password": self.password,
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1855, in post
    extensions=extensions,
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1527, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1618, in send
    history=[],
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
    history=history,
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1700, in _send_handling_redirects
    raise exc
  File "/home/pi/.local/lib/python3.7/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
    await hook(response)
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/authentication.py", line 355, in raise_for_status_event_handler
    await handle_httpstatuserror(ex, log_handler=_LOGGER)
  File "/home/pi/.local/lib/python3.7/site-packages/bimmer_connected/api/utils.py", line 75, in handle_httpstatuserror
    raise _ex_to_raise(_err_message) from ex
bimmer_connected.models.MyBMWAuthError: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)
rikroe commented 1 year ago

I am able to log in to rest_of_world and north_america.

Are you able to login using the MyBMW app? BMW started to enforce password policies, maybe you have to change your password (or have changed already it but missed it here).

olyashok commented 1 year ago

Changed the password. Tried both rest_of_world and north_america.

On Thu, May 11, 2023 at 1:42 PM rikroe @.***> wrote:

I am able to log in to rest_of_world and north_america.

Are you able to login using the MyBMW app? BMW started to enforce password policies, maybe you have to change your password (or have changed already it but missed it here).

— Reply to this email directly, view it on GitHub https://github.com/bimmerconnected/bimmer_connected/issues/533#issuecomment-1544423284, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMBUT7TNI4554G7YFBB3LDLXFUQH7ANCNFSM6AAAAAAX42N7AA . You are receiving this because you authored the thread.Message ID: @.***>

rikroe commented 1 year ago

Also, could you please double check which version of bimmerconnected you're on? The same error message was reported in https://github.com/home-assistant/core/issues/92550 but that was actually a completely different root cause.

Should be fixed in 0.13.2 or HA 2023.5.3 when released.

olyashok commented 1 year ago

0.13.1

On Thu, May 11, 2023 at 4:17 PM rikroe @.***> wrote:

Also, could you please double check which version of bimmerconnected you're on? The same error message was reported in home-assistant/core#92550 https://github.com/home-assistant/core/issues/92550 but that was actually a completely different root cause.

Should be fixed in 0.13.2 or (HA 2023.5.3)[ https://github.com/home-assistant/core/milestone/596] when released.

— Reply to this email directly, view it on GitHub https://github.com/bimmerconnected/bimmer_connected/issues/533#issuecomment-1544618741, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMBUT7SAOKX7NCRVV5AQ2ATXFVCOTANCNFSM6AAAAAAX42N7AA . You are receiving this because you authored the thread.Message ID: @.***>

olyashok commented 1 year ago

Same issue on 0.13.3

On Thu, May 11, 2023 at 4:17 PM rikroe @.***> wrote:

Also, could you please double check which version of bimmerconnected you're on? The same error message was reported in home-assistant/core#92550 https://github.com/home-assistant/core/issues/92550 but that was actually a completely different root cause.

Should be fixed in 0.13.2 or (HA 2023.5.3)[ https://github.com/home-assistant/core/milestone/596] when released.

— Reply to this email directly, view it on GitHub https://github.com/bimmerconnected/bimmer_connected/issues/533#issuecomment-1544618741, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMBUT7SAOKX7NCRVV5AQ2ATXFVCOTANCNFSM6AAAAAAX42N7AA . You are receiving this because you authored the thread.Message ID: @.***>

olyashok commented 1 year ago

DEBUG:asyncio:Using selector: EpollSelector DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False DEBUG:httpx:load_verify_locations cafile='/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/certifi/cacert.pem' DEBUG:bimmer_connected.api.authentication:MyBMWLoginClient kwargs: {'timeout': Timeout(timeout=30.0), 'auth': <bimmer_connected.api.authentication.MyBMWLoginRetry object at 0x7f08429a3850>, 'base_url': 'https://cocoapi.bmwgroup.us', 'headers': {'user-agent': 'Dart/2.18 (dart:io)', 'x-user-agent': 'android(TQ2A.230405.003.B2);bmw;3.3.1(22418);na'}, 'event_hooks': defaultdict(<class 'list'>, {})} DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False DEBUG:httpx:load_verify_locations cafile='/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/certifi/cacert.pem' DEBUG:bimmer_connected.api.authentication:Authenticating with MyBMW flow for North America & Rest of World. DEBUG:httpcore:connection.connect_tcp.started host='cocoapi.bmwgroup.us' port=443 local_address=None timeout=30.0 DEBUG:httpcore:connection.connect_tcp.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7f08428fa160> DEBUG:httpcore:connection.start_tls.started ssl_context=<ssl.SSLContext object at 0x7f0842a063c0> server_hostname='cocoapi.bmwgroup.us' timeout=30.0 DEBUG:httpcore:connection.start_tls.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7f08429b9d90> DEBUG:httpcore:http11.send_request_headers.started request=<Request [b'GET']> DEBUG:httpcore:http11.send_request_headers.complete DEBUG:httpcore:http11.send_request_body.started request=<Request [b'GET']> DEBUG:httpcore:http11.send_request_body.complete DEBUG:httpcore:http11.receive_response_headers.started request=<Request [b'GET']> DEBUG:httpcore:http11.receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Length', b'565'), (b'Content-Type', b'application/json; charset=utf-8'), (b'x-correlation-id', b'c79a351e-2102-4b64-b27f-84febabad893'), (b'x-cluster-mock-used', b'false'), (b'Strict-Transport-Security', b'max-age=31536000; includeSubDomains'), (b'X-Content-Type-Options', b'nosniff'), (b'Content-Security-Policy', b"default-src 'self'"), (b'Request-Context', b'appId=cid-v1:3447961e-979e-4bb9-9a5c-2a729e41a4bb'), (b'Date', b'Sat, 13 May 2023 18:58:44 GMT')]) DEBUG:httpx:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-ucs/v1/presentation/oauth/config "HTTP/1.1 200 OK" DEBUG:httpcore:http11.receive_response_body.started request=<Request [b'GET']> DEBUG:httpcore:http11.receive_response_body.complete DEBUG:httpcore:http11.response_closed.started DEBUG:httpcore:http11.response_closed.complete DEBUG:httpcore:connection.connect_tcp.started host='login.bmwusa.com' port=443 local_address=None timeout=30.0 DEBUG:httpcore:connection.connect_tcp.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7f0842040190> DEBUG:httpcore:connection.start_tls.started ssl_context=<ssl.SSLContext object at 0x7f0842a063c0> server_hostname='login.bmwusa.com' timeout=30.0 DEBUG:httpcore:connection.start_tls.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7f084201e4c0> DEBUG:httpcore:http11.send_request_headers.started request=<Request [b'POST']> DEBUG:httpcore:http11.send_request_headers.complete DEBUG:httpcore:http11.send_request_body.started request=<Request [b'POST']> DEBUG:httpcore:http11.send_request_body.complete DEBUG:httpcore:http11.receive_response_headers.started request=<Request [b'POST']> DEBUG:httpcore:http11.receive_response_headers.complete return_value=(b'HTTP/1.1', 401, b'Unauthorized', [(b'Date', b'Sat, 13 May 2023 18:58:45 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'190'), (b'Connection', b'keep-alive'), (b'x-frame-options', b'SAMEORIGIN'), (b'x-content-type-options', b'nosniff'), (b'cache-control', b'private'), (b'cache-control', b'no-cache, no-store, must-revalidate'), (b'expires', b'0'), (b'pragma', b'no-cache'), (b'Strict-Transport-Security', b'max-age=15724800; includeSubDomains'), (b'x-c2b-pwpolicyconform', b'true'), (b'Access-Control-Allow-Origin', b''), (b'Access-Control-Allow-Headers', b'Authorization, Origin, X-c2b-Authorization, X-c2b-mTAN, X-Requested-With, X-c2b-Sender-Id, X-c2b-External-Id, Content-Type, Accept, Cache-Control, KeyId, x-dtc'), (b'Access-Control-Max-Age', b'3628800'), (b'Access-Control-Allow-Credentials', b'true'), (b'Access-Control-Allow-Methods', b'POST, GET, OPTIONS, PUT, DELETE, HEAD'), (b'Referrer-Policy', b'strict-origin'), (b'x-c2b-request-id', b'rrt-3627472992711536842-b-gea1-25121-67398036-1')]) DEBUG:httpx:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate "HTTP/1.1 401 Unauthorized" DEBUG:httpcore:http11.receive_response_body.started request=<Request [b'POST']> DEBUG:httpcore:http11.receive_response_body.complete DEBUG:httpcore:http11.response_closed.started DEBUG:httpcore:http11.response_closed.complete ERROR:bimmer_connected.api.authentication:MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method) DEBUG:httpcore:connection.close.started DEBUG:httpcore:connection.close.complete DEBUG:httpcore:connection.close.started DEBUG:httpcore:connection.close.complete Traceback (most recent call last): File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 356, in raise_for_status_event_handler response.raise_for_status() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_models.py", line 749, in raise_for_status raise HTTPStatusError(message, request=request, response=self) httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://login.bmwusa.com/gcdm/oauth/authenticate'

rikroe commented 1 year ago

I'm very sorry but I can't help or reproduce. I am able to login to north_america with my test account. Can you log out of your MyBMW and log in using the same credentials?

```log DEBUG:asyncio:Using selector: EpollSelector DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.api.authentication:Authenticating with MyBMW flow for North America & Rest of World. DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-ucs/v1/presentation/oauth/config "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate?interaction-id=4b7854b0-58cc-48ac-b602-05f9f7eed410&client-version=android%28TQ2A.230405.003.B2%29%3Bbmw%3B3.3.1%2822418%29%3Bna "HTTP/1.1 302 Found" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/token "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-vcs/v4/vehicles "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-vcs/v4/vehicles "HTTP/1.1 200 OK" ```
olyashok commented 1 year ago

Yes I can.

DEBUG:asyncio:Using selector: EpollSelector DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False DEBUG:httpx:load_verify_locations cafile='/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/certifi/cacert.pem' DEBUG:bimmer_connected.api.authentication:MyBMWLoginClient kwargs: {'timeout': Timeout(timeout=30.0), 'auth': <bimmer_connected.api.authentication.MyBMWLoginRetry object at 0x7fbb1d24dbe0>, 'base_url': 'https://cocoapi.bmwgroup.us', 'headers': {'user-agent': 'Dart/2.18 (dart:io)', 'x-user-agent': 'android(TQ2A.230405.003.B2);bmw;3.3.1(22418);na'}, 'event_hooks': defaultdict(<class 'list'>, {})} DEBUG:httpx:load_ssl_context verify=True cert=None trust_env=True http2=False DEBUG:httpx:load_verify_locations cafile='/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/certifi/cacert.pem' DEBUG:bimmer_connected.api.authentication:Authenticating with MyBMW flow for North America & Rest of World. DEBUG:httpcore:connection.connect_tcp.started host='cocoapi.bmwgroup.us' port=443 local_address=None timeout=30.0 DEBUG:httpcore:connection.connect_tcp.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7fbb1d1ab100> DEBUG:httpcore:connection.start_tls.started ssl_context=<ssl.SSLContext object at 0x7fbb1d2b0340> server_hostname='cocoapi.bmwgroup.us' timeout=30.0 DEBUG:httpcore:connection.start_tls.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7fbb1d1a2730> DEBUG:httpcore:http11.send_request_headers.started request=<Request [b'GET']> DEBUG:httpcore:http11.send_request_headers.complete DEBUG:httpcore:http11.send_request_body.started request=<Request [b'GET']> DEBUG:httpcore:http11.send_request_body.complete DEBUG:httpcore:http11.receive_response_headers.started request=<Request [b'GET']> DEBUG:httpcore:http11.receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Content-Length', b'565'), (b'Content-Type', b'application/json; charset=utf-8'), (b'x-correlation-id', b'73de722d-65c7-49ad-b7f1-42c87b65c117'), (b'x-cluster-mock-used', b'false'), (b'Strict-Transport-Security', b'max-age=31536000; includeSubDomains'), (b'X-Content-Type-Options', b'nosniff'), (b'Content-Security-Policy', b"default-src 'self'"), (b'Request-Context', b'appId=cid-v1:3447961e-979e-4bb9-9a5c-2a729e41a4bb'), (b'Date', b'Wed, 17 May 2023 23:03:21 GMT')]) DEBUG:httpx:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-ucs/v1/presentation/oauth/config "HTTP/1.1 200 OK" DEBUG:httpcore:http11.receive_response_body.started request=<Request [b'GET']> DEBUG:httpcore:http11.receive_response_body.complete DEBUG:httpcore:http11.response_closed.started DEBUG:httpcore:http11.response_closed.complete DEBUG:httpcore:connection.connect_tcp.started host='login.bmwusa.com' port=443 local_address=None timeout=30.0 DEBUG:httpcore:connection.connect_tcp.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7fbb1c8ea670> DEBUG:httpcore:connection.start_tls.started ssl_context=<ssl.SSLContext object at 0x7fbb1d2b0340> server_hostname='login.bmwusa.com' timeout=30.0 DEBUG:httpcore:connection.start_tls.complete return_value=<httpcore.backends.asyncio.AsyncIOStream object at 0x7fbb1c8ea610> DEBUG:httpcore:http11.send_request_headers.started request=<Request [b'POST']> DEBUG:httpcore:http11.send_request_headers.complete DEBUG:httpcore:http11.send_request_body.started request=<Request [b'POST']> DEBUG:httpcore:http11.send_request_body.complete DEBUG:httpcore:http11.receive_response_headers.started request=<Request [b'POST']> DEBUG:httpcore:http11.receive_response_headers.complete return_value=(b'HTTP/1.1', 401, b'Unauthorized', [(b'Date', b'Wed, 17 May 2023 23:03:22 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'190'), (b'Connection', b'keep-alive'), (b'x-frame-options', b'SAMEORIGIN'), (b'x-content-type-options', b'nosniff'), (b'cache-control', b'private'), (b'cache-control', b'no-cache, no-store, must-revalidate'), (b'expires', b'0'), (b'pragma', b'no-cache'), (b'Strict-Transport-Security', b'max-age=15724800; includeSubDomains'), (b'x-c2b-pwpolicyconform', b'true'), (b'Access-Control-Allow-Origin', b''), (b'Access-Control-Allow-Headers', b'Authorization, Origin, X-c2b-Authorization, X-c2b-mTAN, X-Requested-With, X-c2b-Sender-Id, X-c2b-External-Id, Content-Type, Accept, Cache-Control, KeyId, x-dtc'), (b'Access-Control-Max-Age', b'3628800'), (b'Access-Control-Allow-Credentials', b'true'), (b'Access-Control-Allow-Methods', b'POST, GET, OPTIONS, PUT, DELETE, HEAD'), (b'Referrer-Policy', b'strict-origin'), (b'x-c2b-request-id', b'rrt-7659195717301505051-d-gea1-3519-19733510-1')]) DEBUG:httpx:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate "HTTP/1.1 401 Unauthorized" DEBUG:httpcore:http11.receive_response_body.started request=<Request [b'POST']> DEBUG:httpcore:http11.receive_response_body.complete DEBUG:httpcore:http11.response_closed.started DEBUG:httpcore:http11.response_closed.complete ERROR:bimmer_connected.api.authentication:MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method) DEBUG:httpcore:connection.close.started DEBUG:httpcore:connection.close.complete DEBUG:httpcore:connection.close.started DEBUG:httpcore:connection.close.complete Traceback (most recent call last): File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 356, in raise_for_status_event_handler response.raise_for_status() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_models.py", line 749, in raise_for_status raise HTTPStatusError(message, request=request, response=self) httpx.HTTPStatusError: Client error '401 Unauthorized' for url ' https://login.bmwusa.com/gcdm/oauth/authenticate' For more information check: https://httpstatuses.com/401

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

Traceback (most recent call last): File "/usr/share/hassio/homeassistant/bmw.py", line 30, in asyncio.run(main()) File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/usr/share/hassio/homeassistant/bmw.py", line 26, in main await account.get_vehicles() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/account.py", line 93, in get_vehicles await self._init_vehicles() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/account.py", line 72, in _init_vehicles vehicles_responses: List[httpx.Response] = [ File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/account.py", line 73, in await client.get( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1754, in get return await self.request( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth request = await auth_flow.anext() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 76, in async_auth_flow await self.login() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 114, in login token_data = await self._login_row_na() File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 165, in _login_row_na response = await client.post( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1845, in post return await self.request( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1530, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1617, in send response = await self._send_handling_auth( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1645, in _send_handling_auth response = await self._send_handling_redirects( File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1703, in _send_handling_redirects raise exc File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects await hook(response) File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/authentication.py", line 358, in raise_for_status_event_handler await handle_httpstatuserror(ex, log_handler=_LOGGER) File "/usr/share/hassio/homeassistant/.venv/lib/python3.9/site-packages/bimmer_connected/api/utils.py", line 75, in handle_httpstatuserror raise _ex_to_raise(_err_message) from ex bimmer_connected.models.MyBMWAuthError: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)

On Tue, May 16, 2023 at 2:20 PM rikroe @.***> wrote:

I'm very sorry but I can't help or reproduce. I am able to login to north_america with my test account. Can you log out of your MyBMW and log in using the same credentials?

DEBUG:asyncio:Using selector: EpollSelector DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.api.authentication:Authenticating with MyBMW flow for North America & Rest of World. DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-ucs/v1/presentation/oauth/config "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/authenticate?interaction-id=4b7854b0-58cc-48ac-b602-05f9f7eed410&client-version=android%28TQ2A.230405.003.B2%29%3Bbmw%3B3.3.1%2822418%29%3Bna "HTTP/1.1 302 Found" DEBUG:httpx._client:HTTP Request: POST https://login.bmwusa.com/gcdm/oauth/token "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-vcs/v4/vehicles "HTTP/1.1 200 OK" DEBUG:httpx._client:HTTP Request: GET https://cocoapi.bmwgroup.us/eadrax-vcs/v4/vehicles "HTTP/1.1 200 OK"

— Reply to this email directly, view it on GitHub https://github.com/bimmerconnected/bimmer_connected/issues/533#issuecomment-1550151736, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMBUT7SGQUO5PHA272ZNLWLXGPAOLANCNFSM6AAAAAAX42N7AA . You are receiving this because you authored the thread.Message ID: @.***>

rikroe commented 1 year ago

Unfortunately I cannot help you then. The message you receive is the default message if either username/password are wrong or the library is not up to date with the current MyBMW app.

As I am able to login with credentials for North America, I cannot debug anything I am not able to reproduce.

I've read in some other thread that people were able to use the integration again after setting the refresh_token to null in config/.storage/core.config_entries. But from what I read from the logs, this should not apply to you as you are interacting directly with the library from python.

rikroe commented 1 year ago

Only thing you could try is checking the special characters in you password (see https://github.com/home-assistant/core/issues/92550#issuecomment-1552838437 for an explanation).

olyashok commented 1 year ago

It worked! So I am back up and running now. Changed password again and then changed .config as per your suggestion

On Thu, May 18, 2023 at 8:22 AM rikroe @.***> wrote:

Only thing you could try is checking the special characters in you password (see home-assistant/core#92550 (comment) https://github.com/home-assistant/core/issues/92550#issuecomment-1552838437 for an explanation).

— Reply to this email directly, view it on GitHub https://github.com/bimmerconnected/bimmer_connected/issues/533#issuecomment-1552974052, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMBUT7Q5JNNFKSEAHTNEYO3XGYH6VANCNFSM6AAAAAAX42N7AA . You are receiving this because you authored the thread.Message ID: @.***>

TiddlyWiddly commented 1 year ago

This just started for me yesterday for no reason. I didn’t change my password and I’m still able to login via the mybmw app. Tried uninstalling and reinstalling the integration and when trying to login it tells me “Unknown error occurred”. Doesn’t matter what region I select.

As far as special characters in my password I have a * and @. Would that cause the issue? I haven’t changed it in a while though.

rikroe commented 1 year ago

Please check if your password fulfills the password policy mentioned in https://github.com/home-assistant/core/issues/92318#issuecomment-1532703364.

Otherwise, changing the password seemed to help a lot of people. With 2023.6, it will also be possible to change it from the UI again.

TiddlyWiddly commented 1 year ago

Weird that was it. Changed it and it works. Thank you for maintaining this.

muxiachuixue commented 1 year ago

I also encountered the same issue today. BMW sometimes considers an account suspicious and restricts login, but it is still possible to login on MyBMW. If you capture the traffic, you may obtain logs such as "Your account has been locked, please reset your password." Sometimes, when there is an error in the response content of the login API, it is still possible to return a token.

EspressoNerd commented 1 year ago

I got the same error after I changed my password today. The recommended solutions editing the bmw_connected_drive and setting refresh_token to null entry in config/.storage/core.config_entries didn't work.

Then I tried to delete, reboot Home Aasistent and reinstall the integration and got an unknown error.

Screenshot 2023-05-31 at 23 46 15

According to the logs it seems like the system is running in the login failure even for a new configuration.

2023-05-31 23:53:49.574 ERROR (MainThread) [bimmer_connected.api.authentication] MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)
2023-05-31 23:53:49.611 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 380, in raise_for_status_event_handler
response.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://customer.bmwgroup.com/gcdm/oauth/authenticate'
For more information check: https://httpstatuses.com/401
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
resp = await request_handler(request)
...
mannibis commented 1 year ago

Same issue here. Got the HTTPStatusError Unauthorized. Logged into MyBMW via browser and asked me to change my password. I did, and tried editing the YAML config to change password and set refresh_token to null. Still getting the unauthorized error after restarting HA and trying to reload integration.

Is there no way to obtain a new refresh token? What is the procedure when a password change is needed, since it is not available via UI?

EDIT: Removing and re-installing the integration now results in Unknown error as @EspressoNerd posted above. This is the log entry:

2023-06-01 23:26:30.719 ERROR (MainThread) [bimmer_connected.api.authentication] MyBMW API error: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)
2023-06-01 23:26:30.720 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 380, in raise_for_status_event_handler
    response.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 749, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://login.bmwusa.com/gcdm/oauth/authenticate'
For more information check: https://httpstatuses.com/401
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/bmw_connected_drive/config_flow.py", line 78, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/bmw_connected_drive/config_flow.py", line 43, in validate_input
    await auth.login()
  File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 118, in login
    token_data = await self._login_row_na()
  File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 170, in _login_row_na
    response = await client.post(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1848, in post
    return await self.request(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1530, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1617, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1703, in _send_handling_redirects
    raise exc
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
    await hook(response)
  File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/authentication.py", line 382, in raise_for_status_event_handler
    await handle_httpstatuserror(ex, log_handler=_LOGGER)
  File "/usr/local/lib/python3.10/site-packages/bimmer_connected/api/utils.py", line 79, in handle_httpstatuserror
    raise _ex_to_raise(_err_message) from ex
bimmer_connected.models.MyBMWAuthError: HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)
rikroe commented 1 year ago

Hi guys, I'm sorry but I am not able to reproduce your error.

I am able to login to rest_of_world and north_america regions after having deleted the integration from HA on both 2023.5.4 and the latest beta release.

Please double check and make sure your password is set correctly. Or are there any other security measures you have to go through when loggin in the MyBMW app?

EspressoNerd commented 1 year ago

It's a weird situation. I reset my password again and now the reinstallation is working. Thank you @rikroe for your support.

mannibis commented 1 year ago

Same here. I tried a shorter password with more symbols (15 characters) and it works now. Who knows.

rpooley commented 1 year ago

It failed for me but when I logged into BMW Connected Drive on the web it said I needed to reset my password for security purposes as they enforced stronger rules from the 22/03/2023. It worked fine after this.

CONSULitAS commented 1 year ago

Thanks a lot! Works after changing the Password on the BMW homepage. 👍

mirceadamian commented 1 year ago

I'm facing this problem since a few months now. So lately I've decided to upgrade HA to 2023.7.2. Also spoke with BMW because in my case changing the password was not working (I was stuck in a loop where it was saying everytime that the password change is enforced since 22nd Mar 2023). Last thing I've asked BMW support was to delete my account completely since I was not able to use it even with MyBMW app. Somehow today I can login to the BMW account on the webpage and in the app but still the BMW Connected Drive integration is not able to login. I'm getting this exact message from the title of this ticket in my logs: 2023-07-18 13:13:15.669 INFO (SyncWorker_6) [homeassistant.loader] Loaded bmw_connected_drive from homeassistant.components.bmw_connected_drive 2023-07-18 13:13:54.042 ERROR (MainThread) [bimmer_connected.api.authentication] MyBMWAuthError due to HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)

Tried changing the refresh_token to null. Tried changing the password again (from the webpage and again from the MyBMW app, with less special characters, with less letters). I'm at complete loss what I can try next.

Any suggestions?

mirceadamian commented 1 year ago

Some quick update from my side. BMW deleted my account. Created a new account (using a completely new email address) and added the VIN of one of my BMWs. I can login on the web page, I can login into the MyBMW app, it is still doesn't work on the integration. Same error message:

2023-07-19 12:17:27.258 ERROR (MainThread) [bimmer_connected.api.authentication] MyBMWAuthError due to HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)

BMW is asking me if I can provide a bit more detailed logs. Any idea how to do that?

mirceadamian commented 1 year ago

Some quick update from my side. BMW deleted my account. Created a new account (using a completely new email address) and added the VIN of one of my BMWs. I can login on the web page, I can login into the MyBMW app, it is still doesn't work on the integration. Same error message:

2023-07-19 12:17:27.258 ERROR (MainThread) [bimmer_connected.api.authentication] MyBMWAuthError due to HTTPStatusError: invalid_client - Client authentication failed (e.g., login failure, unknown client, no client authentication included or unsupported authentication method)

BMW is asking me if I can provide a bit more detailed logs. Any idea how to do that?

Just answering to myself: I have installed the Python standalone version and ran it straight from CLI. Same error and some more debug info like in the above comments from other people.

Anyone who got it working through password change can share what kind of characters you used?

rikroe commented 1 year ago

Regarding special characters in the passwords, I once (I think the rest of world app) found this: https://github.com/home-assistant/core/issues/92318#issuecomment-1532703364

Some users also had success by deleting the integration from HA, waiting a day or two and then logging back in (although I cannot imagine why that helps).

github-actions[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

simon-norman commented 10 months ago

Don't know if anyone else found this, but we found accounts that produced the described error worked when the calls were made from a different machine, and even when through a proxy or just changing the wifi - so seems there is an IP address block as at least one cause of the issue.

github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.