guerrerotook / securitas-direct-new-api

This repository contains the new securitas direct API that can be integrated in Home Assistant
Apache License 2.0
78 stars 30 forks source link

[ES] Diverse errors after upgrading to v2.7.5.1 #230

Closed leo8a closed 4 months ago

leo8a commented 5 months ago

After the last update, the integration stopped working correctly on my HA deployment.

Below some of the error logs from the core service (i.e., ha core logs).

2024-05-06 17:16:50.917 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 165, in _execute_request
    error_login: bool = await self._check_errros(response_text)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 182, in _check_errros
    response = json.loads(value)
               ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

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

Traceback (most recent call last):
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 348, in login
    response = await self._execute_request(content, "mkLoginToken")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 171, in _execute_request
    raise SecuritasDirectError(err.msg, None, headers, content) from err

... TRUNCATED ...

ssword, country: $country, lang: $lang, callby: $callby, id: $id, idDevice: $idDevice, idDeviceIndigitall: $idDeviceIndigitall, deviceType: $deviceType, deviceVersion: $deviceVersion, deviceResolution: $deviceResolution, deviceName: $deviceName, deviceBrand: $deviceBrand, deviceOsVersion: $deviceOsVersion, uuid: $uuid) { __typename res msg hash refreshToken legals changePassword needDeviceAuthorization mainUser } }'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/securitas/alarm_control_panel.py", line 203, in async_update_status
    alarm_status = await self.client.update_overview(self.installation)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/securitas/__init__.py", line 414, in update_overview
    reference_id: str = await self.session.check_alarm(installation)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 416, in check_alarm
    await self._check_authentication_token()
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 229, in _check_authentication_token
    await self.login()
  File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 351, in login
    if result_json["data"]:
       ~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

any hint on what the issue could be is appreciated, thanks

danise76 commented 5 months ago

Aren't you having in system/logs another error before that like that one:

Problems decoding response

If you a have it, need to let it cool for a little while, and then relaunch the service and check how often do you update. It's the anti-DDoS that they have in front of the service, that is from INCAPSULA.

rencmbr commented 5 months ago

The same for me in [BR] . The INCPSULA incidents begin to appear in v2.7.5.1. When I downgrade to v.2.7.4.2. they magically disappear.

danise76 commented 5 months ago

The same for me in [BR] . The INCPSULA incidents begin to appear in v2.7.5.1. When I downgrade to v.2.7.4.2. they magically disappear.

I've downgraded [ES] it yesterday to the same version (2.7.4.2) and it works. It was imposible (whatever timing it was set) to get it working for a night. And since it changed it's working back again smoothly with nothing on the logs.

leo8a commented 5 months ago

If you a have it, need to let it cool for a little while, and then relaunch the service and check how often do you update. It's the anti-DDoS that they have in front of the service, that is from INCAPSULA.

@danise76 gotcha, thanks for the tip.

I've downgraded [ES] it yesterday to the same version (2.7.4.2) and it works. It was imposible (whatever timing it was set) to get it working for a night. And since it changed it's working back again smoothly with nothing on the logs.

did the same yesterday and it worked for me as well, maybe this is something that could be improved (possibly introduced by 6eec9e1 but I'm not sure).

@rencmbr thanks for reporting as well.

hopefully folks facing the same issue after upgrading can find this thread

guerrerotook commented 4 months ago

Thanks for sharing about the incpsula error, I will investigate what are the differences between those to tags!

guerrerotook commented 4 months ago

I removed a piece of code that I add for checking on expired login. Please share it this new version works better!

Thanks @leo8a for reporting it.