ReneNulschDE / mbapi2020

Custom Component to integrate MercedesME devices into Home-Assistant
Other
168 stars 32 forks source link

Unknown error on auth with API #112

Closed viseradius closed 1 year ago

viseradius commented 1 year ago

Hi, currently I cannot auth my mercedes account. I receive the message "Unknown error occurred".


Logger: aiohttp.server
Source: custom_components/mbapi2020/oauth.py:238
Integration: mbapi2020 (documentation, issues)
First occurred: 12:30:57 (4 occurrences)
Last logged: 12:35:44

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, 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 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, 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 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 145, 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 253, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/mbapi2020/config_flow.py", line 95, in async_step_pin
    result = await client.oauth.request_access_token(self.data[CONF_USERNAME], pin, nonce)
  File "/config/custom_components/mbapi2020/oauth.py", line 110, in request_access_token
    token_info = await self._async_request("post", url, data=data, headers=headers)
  File "/config/custom_components/mbapi2020/oauth.py", line 242, in _async_request
    raise err
  File "/config/custom_components/mbapi2020/oauth.py", line 238, in _async_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://id.mercedes-benz.com/as/token.oauth2')
svinginum commented 1 year ago

I’m also unable to authorize. “Unknown error”

This error originated from a custom integration.

Logger: aiohttp.server Source: custom_components/mbapi2020/config_flow.py:101 Integration: MercedesME 2020 (documentation, issues) First occurred: 11:54:54 (2 occurrences) Last logged: 12:16:27

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, 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 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, 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 236, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 145, 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 253, in async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/mbapi2020/config_flow.py", line 101, in async_step_pin _LOGGER.debug("Token received") NameError: name '_LOGGER' is not defined

ReneNulschDE commented 1 year ago

@svinginum : Thanks for reporting, my fault - fixed in the new release v0.8.4

ReneNulschDE commented 1 year ago

@viseradius: Could share more details? What is the version that you use? What is the selected region?

svinginum commented 1 year ago

@svinginum : Thanks for reporting, my fault - fixed in the new release v0.8.4

That was quick. It is now working 👍

vwcruiser commented 1 year ago

I’m also unable to authorize. “Unknown error”. Yesterdax my HA crashed. All integrations works fine, only the mbapi2020 doesn't work. I have to Smart EQ and the integration works fine until yesterday before the crash.

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: aiohttp.server Source: custom_components/mbapi2020/oauth.py:238 Integration: MercedesME 2020 (documentation, issues) First occurred: 16:54:42 (4 occurrences) Last logged: 17:04:12

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, 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 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, 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 236, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 145, 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 253, in async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/mbapi2020/config_flow.py", line 95, in async_step_pin result = await client.oauth.request_access_token(self.data[CONF_USERNAME], pin, nonce) File "/config/custom_components/mbapi2020/oauth.py", line 110, in request_access_token token_info = await self._async_request("post", url, data=data, headers=headers) File "/config/custom_components/mbapi2020/oauth.py", line 242, in _async_request raise err File "/config/custom_components/mbapi2020/oauth.py", line 238, in _async_request resp.raise_for_status() File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status raise ClientResponseError( aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://id.mercedes-benz.com/as/token.oauth2')

ReneNulschDE commented 1 year ago

@vwcruiser : I propose that you delete the .mercedesme-token-cache file in your HA-config folder (or in case you are on the latest version, you can use the delete option in the "Configure" dialog of the component too).

Restart your HA, and reauthenticate.

Do you have a or more Smarts only? If yes, the MB component does not work very well with Smarts (or better just by an mistake on the MB Server side) - I propose that you use the Smart Integration (https://github.com/ReneNulschDE/ha-smart-eq-connect)

vwcruiser commented 1 year ago

Hello Rene,

can we talk in german?

I delete the HACS repository, restart HA and install the repository. After a restart of HA I install the integration and it functions well. But I see no entities. Since the last 12 month I worked with your Smart EQ control integration, but at the end of january 2023, the entities didn’t function. I changed to the mbapi2020 and see a lot of entities of my both Smarts! It was wonderful!!!

This ist he log of the Smart EQ Control integration:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: homeassistant.config_entries

Source: custom_components/smarteqconnect/api.py:77

Integration: Smart EQ Connect (documentation, issues)

First occurred: 20:46:12 (1 occurrences)

Last logged: 20:46:12

Error setting up entry smarteqconnect for smarteqconnect

Traceback (most recent call last):

File "/usr/local/lib/python3.10/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 "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection

raise exceptions[0]

File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection

sock = await self._connect_sock(

File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock

await self.sock_connect(sock, address)

File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect

return await fut

File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 505, in _sock_connect

sock.connect(address)

OSError: [Errno 101] Network unreachable

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

Traceback (most recent call last):

File "/config/custom_components/smarteqconnect/api.py", line 74, in _request

async with session.request(method, url, proxy=SYSTEM_PROXY, verify_ssl=VERIFY_SSL, **kwargs) as resp:

File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in aenter

self._resp = await self._coro

File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request

conn = await self._connector.connect(

File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect

proto = await self._create_connection(req, traces, timeout)

File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection

_, proto = await self._create_direct_connection(req, traces, timeout)

File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection

raise last_exc

File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection

transp, proto = await self._wrap_create_connection(

File "/usr/local/lib/python3.10/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 oneapp.microservice.smart.com:443 ssl:default [Network unreachable]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup

result = await component.async_setup_entry(hass, self)

File "/config/custom_components/smarteqconnect/init.py", line 79, in async_setup_entry

masterdata = await smarteq.client.api.get_user_info()

File "/config/custom_components/smarteqconnect/api.py", line 84, in get_user_info

return await self._request("get", "/seqc/v0/users/current")

File "/config/custom_components/smarteqconnect/api.py", line 77, in _request

raise RequestError(f"Error requesting data from {url}: {err}")

custom_components.smarteqconnect.errors.RequestError: Error requesting data from https://oneapp.microservice.smart.com/seqc/v0/users/current: Cannot connect to host oneapp.microservice.smart.com:443 ssl:default [Network unreachable]

Von: Rene Nulsch @.> Gesendet: Sonntag, 26. Februar 2023 18:35 An: ReneNulschDE/mbapi2020 @.> Cc: vwcruiser @.>; Mention @.> Betreff: Re: [ReneNulschDE/mbapi2020] Unknown error on auth with API (Issue #112)

@vwcruiser https://github.com/vwcruiser : I propose that you delete the .mercedesme-token-cache file in your HA-config folder (or in case you are on the latest version, you can use the delete option in the "Configure" dialog of the component too).

Restart your HA, and reauthenticate.

Do you have a or more Smarts only?

— Reply to this email directly, view it on GitHub https://github.com/ReneNulschDE/mbapi2020/issues/112#issuecomment-1445416099 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASFTFTNIPL4QXMI7K2UMH4LWZOH2RANCNFSM6AAAAAAVINJ4C4 . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ASFTFTLJZYWKSHEHWSYHVV3WZOH2RA5CNFSM6AAAAAAVINJ4C6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSWE5GKG.gif Message ID: @. @.> >

viseradius commented 1 year ago

@viseradius: Could share more details? What is the version that you use? What is the selected region?

I used version 0.8.2 and region Europe.

ReneNulschDE commented 1 year ago

@vwcruiser : Yes, let me open a new issue and let us discuss this in a new one.

ReneNulschDE commented 1 year ago

@viseradius : Please update to version 0.8.4 and I propose that you delete the .mercedesme-token-cache file in your HA-config folder (or in case you are on the latest version, you can use the delete option in the "Configure" dialog of the component too).

Restart your HA. Follow the requested reauthentication process.

I have checked this with my account in Europe and in general its working.

viseradius commented 1 year ago

It seems to be working with version 0.8.4. thanks.