indykoning / PyPi_GrowattServer

MIT License
70 stars 32 forks source link

Still getting error 403 with version 1.5.0 #78

Open fisken opened 4 months ago

fisken commented 4 months ago

Hi,

I just updated to 1.5.0; the previous versions last worked for me a few months ago. I changed the URL with the previous version but had no luck.

After updating, I'm still getting:

HTTPError Traceback (most recent call last) ipython-input-4-06dc7ac3e99d in module 10 11 api = growattServer.GrowattApi(False, "adgahtwq3241") ---> 12 login_response = api.login(username, user_pass) 13 print("Add random ID to default User-Agent") 14 print("User-Agent: %s\nLogged in User id: %s" % (api.agent_identifier, login_response['userId'])) ... Further down: HTTPError: 403 Client Error: Forbidden for url: https://openapi.growatt.com/newTwoLoginAPI.do

I have tried with: api = growattServer.GrowattApi(False, "something") api = growattServer.GrowattApi(True) api = growattServer.GrowattApi()

All give the same HTTPError: 403.

Am I doing something wrong? I'm a Python novice.

GraemeDBlue commented 4 months ago

Same issue here, only found this server yesterday

Nbondb commented 4 months ago

Same herer, running on termux on android 10. File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/growatt/mymain", line 19, in login_response = api.login(username, password) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/growatt/init.py", line 131, in login response = self.session.post(self.get_url('newTwoLoginAPI.do'), data={ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 677, in post myret= self.request("POST", url, data=data, json=json, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 622, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 752, in send r = dispatch_hook("response", hooks, r, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/hooks.py", line 30, in dispatch_hook _hook_data = hook(hook_data, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/growatt/init.py", line 41, in 'response': lambda response, *args, **kwargs: response.raise_for_status() ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/models.py", line 1024, in raise_for_status raise HTTPError(http_error_msg, response=self)requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://openapi.growatt.com/newTwoLoginAPI.do

Nbondb commented 4 months ago

I don't know if relevant but I couldn't run setup.py because it couldn't find setuptools

GraemeDBlue commented 4 months ago

I've tried https://github.com/PLCHome/growatt and this works fine so will see if I can update they python to work the same

Nbondb commented 4 months ago

Now managed to run setup.py but no difference. I'm inexperienced in python and http, but added prints into the code and notice that there is no Authorization element in the http header, is that the problem?

Nbondb commented 3 months ago

Is it feasible to convert it to Python? Is it likely to take a long time? Many thanks for your efforts.

I've tried https://github.com/PLCHome/growatt and this works fine so will see if I can update they python to work the same

GraemeDBlue commented 3 months ago

Is it feasible to convert it to Python? Is it likely to take a long time? Many thanks for your efforts.

I've tried https://github.com/PLCHome/growatt and this works fine so will see if I can update they python to work the same

Its a lot of work but I will see what I can do, Python not my daily language so will be a bit of a learning curve for me first

sledgemhammer commented 3 months ago

you have to change <agent_identifier => value to something real the default in the example is blacklisted

ericsfraga commented 3 months ago

I also am having problems connecting. If I use one server (openapi-us.growatt.com), I get Username or Password Error. If I use server.growatt.com, I get 403 Client Error: Forbidden for url [...].

This is with True as the argument to the GrowattApi function. If I need to specify an actual agent identifier, can somebody suggest what I should use?

For context, I used the 1.2 version of this package for some time but it quit working a long time ago now. I can access the data via the web or the Android app so I know my username/password are okay.

Thank you.

Update: the JavaScript code referred to above works just fine. I can use that for what I need but a python script would be better overall.

sledgemhammer commented 3 months ago

I also am having problems connecting. If I use one server (openapi-us.growatt.com), I get Username or Password Error. If I use server.growatt.com, I get 403 Client Error: Forbidden for url [...].

This is with True as the argument to the GrowattApi function. If I need to specify an actual agent identifier, can somebody suggest what I should use?

For context, I used the 1.2 version of this package for some time but it quit working a long time ago now. I can access the data via the web or the Android app so I know my username/password are okay.

Thank you.

Update: the JavaScript code referred to above works just fine. I can use that for what I need but a python script would be better overall.

Did you change the agent identifier in the pyhton script to a real current chrome or other real agent string ? I had exactly the same until i changed that. Note that the servers in use are bound to global regions os you cannot random change that. Pyhton running flawles here every x minutes after that change.

sledgemhammer commented 3 months ago

Had the same u til i changed the agent.

flopp999 commented 3 months ago

https://github.com/indykoning/PyPi_GrowattServer/blob/master/growattServer/__init__.py#L28 Change to "Chrome" is working for me

flopp999 commented 3 months ago

Or use below when initialise to use a random agentID. Below is copied from Readme api = growattServer.GrowattApi(True)

ericsfraga commented 3 months ago

Thank you. I did try the random ID case (i.e. with True as an argument) but that did not help. I haven't tried actually specifying a string for the agent. The javascript code is working, as I indicated in my update to the post, and that's good enough for me for the moment.

molekuul commented 3 weeks ago

I have the same problem, I also get a similar error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/growattServer/__init__.py", line 131, in login
    response = self.session.post(self.get_url('newTwoLoginAPI.do'), data={
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/requests/sessions.py", line 710, in send
    r = dispatch_hook("response", hooks, r, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/requests/hooks.py", line 30, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/lib/python3.11/site-packages/growattServer/__init__.py", line 41, in <lambda>
    'response': lambda response, *args, **kwargs: response.raise_for_status()
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jorisweijters/.pyenv/versions/3.11.3/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://openapi.growatt.com/newTwoLoginAPI.do
>>>

please help,

Kind regards, Joris Weijters

sledgemhammer commented 2 weeks ago

I have the same problem, I also get a similar error:



please help,

Kind regards, Joris Weijters

in the script by default the agent identifier is set to a not existing one : that is not accepted by the growatt server

You can change it with an argument as suggested in the readme (see flop9999)

Or you can change the line iwhere it is defined into a real agent, but then you have to edit the python package in your sitepackages directory. For all your error lines the cause is the agent identifier thats not accepted.

(I hope this gives you a hint how to proceed.)

molekuul commented 2 weeks ago

@sledgemhammer Thanks for you comments, I can get further with this.