Open Hazkarax opened 2 months ago
Hi @Hazkarax,
In your code, you are currently not really using the session object you create. This would have to be passed through the session
parameter in the constructor.
In my experience, the easiest way to keep an application running for a long time (in my case nearly 2 years without a CAPTCHA test) is by limiting the number of logins to a minimum.
I've updated the README.md and added instructions how to use two new calls to ensure that a session is kept alive. Essentially, you need to call is_session_active
around every 10 seconds, and keep_alive
every 30 seconds.
In my case, this allowed me to use the same session over many months.
Thanks for your reply. I have tried to update the code, and this is what happens.
When I run this version of the code:
from fusion_solar_py.client import FusionSolarClient
import requests
# log into the API - with proper credentials...
session = requests.Session()
client = FusionSolarClient(
‘Username’,
‘Password’,
huawei_subdomain="uni004eu5",
session=session
)
plant_ids = client.get_plant_ids()
print(f"Found {len(plant_ids)} plants")
I get this error message.
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/fusion_solar_py/client.py", line 456, in get_station_list
obj_tree = r.json()
requests.exceptions.JSONDecodeError: Expecting value: line 6 column 1 (char 5)
At r.json, the API doesn’t return a json but a HTML-page which appears to be a login page, and looks like this:
When I don't use the session, it works just fine.
I am trying to continuously run a script to provide live production data of a solar plant, which is to be displayed on a raspberry which will run continuously. After approximately 20-30 minutes, its stops updating, which I assume is due to the API returning a captcha.
I have tried to resolve this error both by re-using the session and by using captcha. However, the captcha ad-on cannot be installed as pip can not find any matching packages. Running the code with the captcha config therefore returns an error after 20 minutes when the captcha is needed.
I do not quite understand how to re-use the session either, as it gives an error when it tries to read a json. How does a full implementation of a session re-use look like?
The code in which I am trying to implement the following looks like this. Adding the recaptcha to the client gives an error after 20 minutes when a verification is requested, and the implementations I have tried of a session re-use have provided an error when reading the json.