home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.58k stars 29.91k forks source link

Growatt server error after upgrade #71577

Closed thoompje closed 2 years ago

thoompje commented 2 years ago

The problem

Hello,

Growatt server is not working anymore after upgrade to 5.3

Logger: aiohttp.server
Source: components/growatt_server/config_flow.py:50
First occurred: 11:01:53 AM (7 occurrences)
Last logged: 11:09:06 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='server.growatt.com', port=443): Max retries exceeded with url: /newLoginAPI.do (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/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 79, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 205, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 109, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, 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 "/usr/src/homeassistant/homeassistant/components/growatt_server/config_flow.py", line 50, in async_step_user
    login_response = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/growattServer/__init__.py", line 115, in login
    response = self.session.post(self.get_url('newLoginAPI.do'), data={
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='server.growatt.com', port=443): Max retries exceeded with url: /newLoginAPI.do (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))

What version of Home Assistant Core has the issue?

core-5.3

What was the last working version of Home Assistant Core?

core-4,7

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Growatt

Link to integration documentation on our website

https://www.home-assistant.io/integrations/growatt_server

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

growatt_server documentation growatt_server source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @indykoning, @muppet3000, @jasperplant, mind taking a look at this issue as it has been labeled with an integration (growatt_server) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

thompy93 commented 2 years ago

I can confirm seeing the same issue on Core 4.7

thoompje commented 2 years ago

I can confirm seeing the same issue on Core 4.7

Ahh oke, then it is coincidentally after the upgrade that i have this issue. Then it was maybe before but didn't seen it.

thompy93 commented 2 years ago

I can confirm seeing the same issue on Core 4.7

Ahh oke, then it is coincidentally after the upgrade that i have this issue. Then it was maybe before but didn't seen it.

It was working fine for me yesterday. Today it went unavaiblable around 09:00 GMT+2

rumunn95 commented 2 years ago

Same problem.

muppet3000 commented 2 years ago

The central growatt server is down: https://server.growatt.com/

That's where all the information is pulled from, the integration will only work when that server is up. Oddly the android app is still working, so they may just be having problems with the core website.

I'll investigate more later.

rumunn95 commented 2 years ago

yep android app working fine... strange. For this moment only way is waiting for serwer up.

Joooost commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working.

I have changed the URL manually in the core.config_entries and after a restart the integration was working again.

image

My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

rumunn95 commented 2 years ago

https://oss.growatt.com/ is working.

thoompje commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working.

I have changed the URL manually in the core.config_entries and after a restart the integration was working again.

My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

Thanks for contacting them!!

Schelin78 commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working. I have changed the URL manually in the core.config_entries and after a restart the integration was working again. My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

Thanks for contacting them!!

Same here! can´t find core.config_entries

rumunn95 commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working. I have changed the URL manually in the core.config_entries and after a restart the integration was working again. My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

Thanks for contacting them!!

Same here! can´t find core.config_entries

me too ;(

Joooost commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working. I have changed the URL manually in the core.config_entries and after a restart the integration was working again. My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

Thanks for contacting them!!

Same here! can´t find core.config_entries

Within the config directory there is a hidden directory called ".storage"

Schelin78 commented 2 years ago

Same here since +/- 8:30 AM CET, IOS APP and https://server-api.growatt.com are working. I have changed the URL manually in the core.config_entries and after a restart the integration was working again. My guess is that the mobile apps are using the api url. Maybe this url should be added in the config as well, first wait till the main URL is back again. I have contacted service via mail, let's wait for their reaction

Thanks for contacting them!!

Same here! can´t find core.config_entries

Within the config directory there is a hidden directory called ".storage"

Thanks, how do I show hidden directory with File editor?

Joooost commented 2 years ago

Using Windows:

View --> Options --> Views: there should be a setting. Or just simple type the path in the addressbar: [IP/hostname]\config\ .storage

PS: please make a backup of the file before editing and be careful making such changes.

muppet3000 commented 2 years ago

I agree that it would be very handy to be able to change this, I though we provided a drop-down in a recent version of the integration. In this specific instance I think that the Growatt server has gone down, but, the hass integration could be more graceful in handling it.

I'm currently at work, however I can look at some improvements this evening to see how we can better handle this scenario. In the meantime it looks like you've got some work-arounds going on.

rumunn95 commented 2 years ago

so, only samba or terminal?

Joooost commented 2 years ago

Both should work just fine. Using terminal addon in HAOS: cd config/.storage and use nano to edit the file.

PS: please make a backup of the file before editing and be careful making such changes.

bigfloor commented 2 years ago

Awesome guys, workaround worked for me ! A code change would be very welcome, just so we don't have to mess around the core config files manually (and then could break things). Kind of weird on the Growatt side though, that they have 2 different infra structures pointing to the same data. Here's a view DNS wise:

dig server-api.growatt.com

; <<>> DiG 9.10.6 <<>> server-api.growatt.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7202 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;server-api.growatt.com. IN A

;; ANSWER SECTION: server-api.growatt.com. 145 IN A 47.91.67.221

;; Query time: 89 msec ;; SERVER: 1.1.1.1#53(1.1.1.1) ;; WHEN: Mon May 09 12:20:26 CEST 2022 ;; MSG SIZE rcvd: 67

And the official one (which is used in the Growatt integration into HA):

dig server.growatt.com

; <<>> DiG 9.10.6 <<>> server.growatt.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31723 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;server.growatt.com. IN A

;; ANSWER SECTION: server.growatt.com. 548 IN CNAME server.growatt.com.w.kunlunea.com. server.growatt.com.w.kunlunea.com. 60 IN A 8.48.85.219

;; Query time: 300 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Mon May 09 12:20:20 CEST 2022 ;; MSG SIZE rcvd: 110

muppet3000 commented 2 years ago

Yeah Growatt are a complete anomaly, it wouldn't surprise me if the page just randomly re-appears tomorrow when China's timezones means that someone is in an office and realises. Likewise, if wouldn't surprise me at all if it never came back!

I'm thinking I can implement some logic to say "if the first URL doesn't work try a fallback". I haven't looked at that code for a while so I need to remember what the existing logic is.

flinkebernt commented 2 years ago

The Shinephone app is working and I can log into server-api.growatt.com, but none of my Growatt WiFi-X modules are sending any data to Growatt at the moment either. Last update was about three hours ago.

DutchKillerbee commented 2 years ago

https://server-api.growatt.com/ should be the default if you ask me What I did is after removing the Growatt integration: -.- I modified the SERVER_URLS constant in the const.py file in the homeassistant/components/growatt_server directory -.- Removed the files in the homeassistant/components/growatt_server/pycache dir -.- Restarted home assistant and added the Growatt server integration I used the https://server-api.growatt.com/ URL and logged in. No issues and all my sensors were back

thoompje commented 2 years ago

const.py file in the homeassistant/components/growatt_server directory

Where did you do this? I'm using dockerd homeassistant and now in the terminal but can't find the folder growatt_server

DutchKillerbee commented 2 years ago

The Shinephone app is working and I can log into server-api.growatt.com, but none of my Growatt WiFi-X modules are sending any data to Growatt at the moment either. Last update was about three hours ago.

I don't have this issue. I have all the data in the ShinePhone app and all the data in HA.

DutchKillerbee commented 2 years ago

const.py file in the homeassistant/components/growatt_server directory

Where did you do this? I'm using dockerd homeassistant and now in the terminal but can't find the folder growatt_server

I installed HA manually on the pi and the file was located here /srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/growatt_server

adriaan144 commented 2 years ago

core.config_entries edit method using https://server-api.growatt.com/ worked for me. Thanks

thoompje commented 2 years ago

const.py file in the homeassistant/components/growatt_server directory

Where did you do this? I'm using dockerd homeassistant and now in the terminal but can't find the folder growatt_server

I installed HA manually on the pi and the file was located here /srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/growatt_server

Only have bash-5.1# ls init.py pycache

in that folder

Joooost commented 2 years ago

Looks like https://server.growatt.com is back

image

thoompje commented 2 years ago

Looks like https://server.growatt.com is back

image

Yeah looks like everything is working again.

muppet3000 commented 2 years ago

All, working for me now as well. I'll postpone my evening hackathon tonight in that case, but I will take a look through the code to see what we can do to accommodate this in the integration. There's a part of me that wants to say that this is a problem with growatt and not the integration, that said, it has happened a few times before so a little bit of preventative coding wouldn't go amiss.

SirLouen commented 2 years ago

Is this integration made for Shinebox with ShineLink, right?

malosaa commented 2 years ago

sometimes this add-on will fail to update.

As it is working, but sometimes i look at energy and nothing is displayed.. i alway need to reload the plugin and then it works.

This always happens after a restart or HASS upgrade..

indykoning commented 2 years ago

Is this integration made for Shinebox with ShineLink, right?

I personally have no experience with this device, but as it's connecting using the internal API of the ShinePhone app as long as it's available in that app it should work.

If it doesn't work like that it may be possible to write your own integration for it, or possibly skip the middleman and DIY it with https://esphome.io/components/sensor/growatt_solar.html

sometimes this add-on will fail to update.

As it is working, but sometimes i look at energy and nothing is displayed.. i alway need to reload the plugin and then it works.

This always happens after a restart or HASS upgrade..

I haven't had this experience myself, do you see anything in the logs about the integration? It may be possible that the API may have been down at that time

dsl10007 commented 2 years ago

Did they change something again, i updated my app earlier today, and now the integration fails completely.

App is working fine it seems, so i gues sthey changed something ?

`Error while setting up growatt_server platform for sensor

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform await asyncio.shield(task) File "/usr/src/homeassistant/homeassistant/components/growatt_server/sensor.py", line 74, in async_setup_entry devices, plant_id = await hass.async_add_executor_job(get_device_list, api, config) File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/growatt_server/sensor.py", line 42, in get_device_list login_response = api.login(config[CONF_USERNAME], config[CONF_PASSWORD]) File "/usr/local/lib/python3.9/site-packages/growattServer/init.py", line 119, in login data = json.loads(response.content.decode('utf-8'))['back'] File "/usr/local/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.9/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) `

DutchKillerbee commented 2 years ago

Same issue here. I tried a different servers such as https://server-api.growatt.com but no luck....

thoompje commented 2 years ago

Same problem.... Pfff a lot of problems with growatt with the last major release. Can someone take a look on this issue!?

nsmits commented 2 years ago

See also #73503

muppet3000 commented 2 years ago

Hi All, this looks like it's unrelated to latest changes to HomeAssistant (I'm running a much older version of home assistant and have the same issue). This looks like a change has been made on the server side of Growatt. I'll report back shortly but this is likely to require a change to the library myself and @indykoning maintain which the Growatt Integration for homeassistant makes use of. Once we've worked out what has changed on the API I'll see if we can issue a recommended change/hack that people can make until the official fix is live.

muppet3000 commented 2 years ago

If anyone's interested to follow progress on the library depend on I'll report it over here: https://github.com/indykoning/PyPi_GrowattServer/issues/28

muppet3000 commented 2 years ago

Posted a more detailed update over on the https://github.com/indykoning/PyPi_GrowattServer/issues/28#issuecomment-1155738553 ticket however, for home-assistant specific stuff:

  1. I have temporarily hacked my copy of homeassistant to make this work with the fix that will be put into the upstream library
  2. I use a docker based installation so have performed the following by mounting files into the container, but the following steps should help people with Home Assistant OS (or other) installations.

File that needs to be changed: /usr/local/lib/python3.9/site-packages/growattServer/__init__.py @ line 115 Change: newLoginAPI.do to newTwoLoginAPI.do then restart home-assistant.

Please don't ask me specifics for your installation as I'm not a home-assistant expert, I just know my way around the docker based installation. If there are people that get this work-around working on the OS or application version of home-assistant, please feel free to post better instructions.

Note - if you're using a docker installation restarting home-assistant means restarting the container which will undo the change. I worked around this by mounting in a temporary directory over the top of the /usr/local/lib/python3.9/site-packages/growattServer/ directory with the hacked version of the library in it.

I hope that helps people temporarily until the upstream library has it's fix published and we can integrate it into home-assistant. I will update accordingly and re-direct any new tickets that are logged with this issue to this one so that we have a single chain for this.

HoekieN commented 2 years ago

Posted a more detailed update over on the indykoning/PyPi_GrowattServer#28 (comment) ticket however, for home-assistant specific stuff:

  1. I have temporarily hacked my copy of homeassistant to make this work with the fix that will be put into the upstream library
  2. I use a docker based installation so have performed the following by mounting files into the container, but the following steps should help people with Home Assistant OS (or other) installations.

File that needs to be changed: /usr/local/lib/python3.9/site-packages/growattServer/__init__.py @ line 115 Change: newLoginAPI.do to newTwoLoginAPI.do then restart home-assistant.

Please don't ask me specifics for your installation as I'm not a home-assistant expert, I just know my way around the docker based installation. If there are people that get this work-around working on the OS or application version of home-assistant, please feel free to post better instructions.

Note - if you're using a docker installation restarting home-assistant means restarting the container which will undo the change. I worked around this by mounting in a temporary directory over the top of the /usr/local/lib/python3.9/site-packages/growattServer/ directory with the hacked version of the library in it.

I hope that helps people temporarily until the upstream library has it's fix published and we can integrate it into home-assistant. I will update accordingly and re-direct any new tickets that are logged with this issue to this one so that we have a single chain for this.

Thanks for posting the quick fix, it seems to work again, i used portainer to connect to the docker container and edit the file

muppet3000 commented 2 years ago

Great to hear this is a good fix for at least one other person :). It's late here so I'm now going to bed, but I'll check in on updates tomorrow in case it doesn't fix it for everyone.

sohnvonoff commented 2 years ago

Hi, how to install Growatt-Integration with alternate Serverpath (e.g. https://server-api.growatt.com) Many thanks.

weltzien commented 2 years ago

Hi,

i got the same problem, atfer hours of looking for a fault in my firewall and dns configuration i found this thread :) if home assistant is not running in a container, how can we fix the problem?

best regards

chris

Schelin78 commented 2 years ago

Hi

Is it growatt or HA problem?

chrisp250 commented 2 years ago

I don't think it's a "problem", as in a bug on either side. I think Growatt might have changed their application and HA is no longer able to extract the data until updated to handle the new format.

thoompje commented 2 years ago

I don't think it's a "problem", as in a bug on either side. I think Growatt might have changed their application and HA is no longer able to extract the data until updated to handle the new format.

Exactly! Did someone already made an fix available for the coming release of HA? Hopefully they will approve if asap.

Roos-AID commented 2 years ago

Great that a fix is to arrive. But in meantime, how can I do this

I use a docker based installation so have performed the following by mounting files into the container,

I use docker on Synology NAS, but would like to get a bit more detailed instruction how to do this. I have a patched version of the specific file, but how can I mount this ?
Thanks for help.

Roos-AID commented 2 years ago

Well, I found out myself a different solution. In Docker container, started BASH shell , used VI to change the file. Saved and restarted the container.

Thanks for all hints.