erikkastelec / hass-WEM-Portal

Custom component for retrieving sensor information from Weishaupt WEM Portal
MIT License
44 stars 9 forks source link

403 Client Error: Forbidden for url: https://www.wemportal.com/app/Account/Login #78

Open M3d1c5 opened 10 months ago

M3d1c5 commented 10 months ago

Hi guys!

The integration has not been able to log on to the WEM portal for a few days. First, the WEM portal was completely down and there was also a 403 error when trying to log in with a browser. This bug was apparently fixed over the weekend. However, the URL calling the integration still seems to be throwing a 403 error. Possibly Weishaupt changed something?

Logger: custom_components.wemportal
Source: custom_components/wemportal/wemportalapi.py:142
Integration: Weishaupt WEM Portal (documentation, issues)
First occurred: 19. August 2023 um 20:50:53 (3528 occurrences)
Last logged: 12:24:11

Creating new wemportal api instance
Error fetching data from wemportal
Traceback (most recent call last):
  File "/config/custom_components/wemportal/wemportalapi.py", line 195, in api_login
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.wemportal.com/app/Account/Login

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

Traceback (most recent call last):
  File "/config/custom_components/wemportal/wemportalapi.py", line 88, in fetch_data
    self.api_login()
  File "/config/custom_components/wemportal/wemportalapi.py", line 208, in api_login
    raise ForbiddenError(
custom_components.wemportal.exceptions.ForbiddenError: WemPortal forbidden error: Server returned internal status code:  and message: 

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

Traceback (most recent call last):
  File "/config/custom_components/wemportal/coordinator.py", line 47, in _async_update_data
    x = await self.hass.async_add_executor_job(self.api.fetch_data)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/wemportal/wemportalapi.py", line 142, in fetch_data
    raise WemPortalError from exc
custom_components.wemportal.exceptions.WemPortalError
dm82m commented 10 months ago

No issue here, restarted server and log is clean and weishaupt data is there.

M3d1c5 commented 10 months ago

That is very strange. I have completely removed the integration, restarted the system and then tried to add the integration again. That does not work either. The same error 403 appears in the log.

The smartphone app and the web interface work.

Is there anything I can check?

Logger: custom_components.wemportal.config_flow
Source: custom_components/wemportal/wemportalapi.py:208
Integration: Weishaupt WEM Portal (documentation, issues)
First occurred: 14:27:37 (1 occurrences)
Last logged: 14:27:37

Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/wemportal/wemportalapi.py", line 195, in api_login
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://www.wemportal.com/app/Account/Login

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

Traceback (most recent call last):
  File "/config/custom_components/wemportal/config_flow.py", line 66, in async_step_user
    info = await validate_input(self.hass, user_input)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/wemportal/config_flow.py", line 39, in validate_input
    await hass.async_add_executor_job(api.api_login)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/wemportal/wemportalapi.py", line 208, in api_login
    raise ForbiddenError(
custom_components.wemportal.exceptions.ForbiddenError: WemPortal forbidden error: Server returned internal status code:  and message: 
M3d1c5 commented 10 months ago

Is it possible that Weishaupt has banned my fixed IP address? I read in Issue 68 that this has happened before.

My 5 year licence had expired and it took me a few days to get a new licence. During that time Home Assistant kept trying to access the API. Could this be a reason why I was banned?

The normal WEM Portal web interface works, the WEM Portal smartphone app also works, only the Home Assistant integration no longer works.

dm82m commented 10 months ago

I thought about that and yes it is possible. You could write the support and explain the issue

erikkastelec commented 10 months ago

This would be the most likely scenario, as it seems that you are the only one experiencing this issue.

When my IP was banned in the past, I got the same error, but I am not sure if I was able to access the website.

M3d1c5 commented 10 months ago

Weishaupt replied to my email that my IP address was indeed blocked. It has now been unblocked and the integration is working again. I was also informed that IP addresses are always blocked if 10000 requests or IP packets are exceeded within 12 hours.

What does this look like with the integration? Does it adhere to the configured API scan interval even if an error occurs during access, such as an expired licence? In my case, the expired licence led to this problem.

erikkastelec commented 10 months ago

Integration does not follow API scan interval when failing so this is the reason for your problem. Will leave this issue open until I implement a fix. Thank you for bringing this to my attention.