macxq / foxess-ha

Home Assistant & FoxESS integration. Monitor you photovoltaic installation directly from HA ☀️ ⚡️
114 stars 36 forks source link

Not able to reach login page #72

Open bboguszewicz opened 2 years ago

bboguszewicz commented 2 years ago

Hi all, from few days I am experiencing the problem where I can't reach login page. Here's the log output:

2022-08-17 11:10:59.604 ERROR (MainThread) [homeassistant.components.rest.data] Error fetching data: https://www.foxesscloud.com/c/v0/user/login failed with
2022-08-17 11:10:59.613 ERROR (MainThread) [custom_components.foxess.sensor] Unable to login to FoxESS Cloud - No data recived
2022-08-17 11:10:59.623 ERROR (MainThread) [custom_components.foxess.sensor] Unexpected error fetching FoxESS data: 'bool' object has no attribute 'encode'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
return await self.update_method()
File "/config/custom_components/foxess/sensor.py", line 139, in async_update_data
await getAddresbook(hass, headersData, allData, deviceID, username, hashedPassword,0)
File "/config/custom_components/foxess/sensor.py", line 219, in getAddresbook
await restAddressBook.async_update()
File "/usr/src/homeassistant/homeassistant/components/rest/data.py", line 60, in async_update
response = await self._async_client.request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 1514, in request
request = self.build_request(
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 345, in build_request
headers = self._merge_headers(headers)
File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 412, in _merge_headers
merged_headers.update(headers)
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 198, in update
headers = Headers(headers)
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 69, in __init__
self._list = [
File "/usr/local/lib/python3.10/site-packages/httpx/_models.py", line 73, in <listcomp>
normalize_header_value(v, encoding),
File "/usr/local/lib/python3.10/site-packages/httpx/_utils.py", line 54, in normalize_header_value
return value.encode(encoding or "ascii")
AttributeError: 'bool' object has no attribute 'encode'

Could you help me understand what might be wrong here ? It was working correctly and then it just stopped. Thanks!

mhzawadi commented 2 years ago

just updated to 2022.09 and also getting issues

Logger: custom_components.foxess.sensor
Source: custom_components/foxess/sensor.py:164
Integration: foxess ([documentation](https://github.com/macxq/foxess-ha), [issues](https://github.com/macxq/foxess-ha/issues))
First occurred: 16:02:15 (1 occurrences)
Last logged: 16:02:15

Unable to login to FoxESS Cloud - No data recived
Logger: homeassistant.components.rest.data
Source: components/rest/data.py:74
Integration: RESTful ([documentation](https://www.home-assistant.io/integrations/rest), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+rest%22))
First occurred: 16:02:15 (1 occurrences)
Last logged: 16:02:15

Error fetching data: https://www.foxesscloud.com/c/v0/user/login failed with
mhzawadi commented 1 year ago

I have good news, I have a curl request that works and returns me a token

curl -X POST \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 OPR/89.0.4447.83', \
-H 'Accept: application/json, text/plain, */*' \
-H 'lang: en' \
-H 'sec-ch-ua-platform: macOS' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://www.foxesscloud.com/login?redirect=/' \
-H 'Accept-Language: en-US;q=0.9,en;q=0.8,de;q=0.7,nl;q=0.6' \
-H 'Connection: keep-alive' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'signature: e5677b71870be075b2b0ede7bafaff5d.5245784' \
-H 'timestamp: 1664016309488' \
-H 'token: ' \
-d @data.json \
https://www.foxesscloud.com/c/v0/user/login

the data.json file

{
    "user": "USERNAME",
    "password": "PASSWORD"
}
mhzawadi commented 1 year ago

and getting raw data

curl -X POST \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 OPR/89.0.4447.83', \
-H 'Accept: application/json, text/plain, */*' \
-H 'lang: en' \
-H 'sec-ch-ua-platform: macOS' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://www.foxesscloud.com/login?redirect=/' \
-H 'Accept-Language: en-US;q=0.9,en;q=0.8,de;q=0.7,nl;q=0.6' \
-H 'Connection: keep-alive' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'signature: 7e45eaaa5343cf62cee9c8bec3c0a113.5245784' \
-H 'timestamp: 1664016314077' \
-H 'token: TOKEN' \
-d @raw.json \
https://www.foxesscloud.com/c/v0/plant/history/raw

the raw.json

{
    "stationID": "e85fa7c2-2f04-4b3a-a9bd-07423d940ca4",
    "variables": [
        "generationPower",
        "feedinPower",
        "loadsPower"
    ],
    "timespan": "day",
    "beginDate": {
        "year": 2022,
        "month": 9,
        "day": 24,
        "hour": 10,
        "minute": 0,
        "second": 0
    }
}
bboguszewicz commented 1 year ago

@mhzawadi how did you calculate the signature ? To be precise I think I know how to calculate, but what data is used to generate the signature and how to get it :)

mhzawadi commented 1 year ago

I didn't, I robbed it from my browser session.

I did have a look at some documents that are on other issues and couldn't work out how

bboguszewicz commented 1 year ago

Would you have the time and energy to briefly tell me how to do it :) ? I'm an embedded software enginner and lacking a bit of know-how in terms of web applications. I tried to find something in chrome console and the only thing I found was the signature.js, but couldn't find what I needed

mhzawadi commented 1 year ago

sure, you login to the foxesscloud site. open the dev tools (option+command+i on a mac), click the network tab and reload the page. scroll down the list of loaded files till you see access, click that and scroll to the bottom of the headers tab.

On a mac I can right click the signature and copy the value

Hope that helps you out

image

bboguszewicz commented 1 year ago

Thanks a lot I was able to find it, but still failing yet with fake requests. Will investigate further, thanks for the help :)

macxq commented 1 year ago

@bboguszewicz does this issue exist in the newest version v0.17?

bboguszewicz commented 1 year ago

Unluckily no, have a timeout on login page Timeout while fetching data: https://www.foxesscloud.com/c/v0/user/login

bboguszewicz commented 1 year ago

I have also checked on 0.18 and the issue is still in place for me. Just to let you know I have made a workaround by using two shelly 3em which gives me much more flexibility and granularity anyway, but of course if you would need any help with testing let me know :)