Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP 403 on login due to auth change ? #38

Open
sledgemhammer opened this issue Oct 1, 2023 · 16 comments
Open

HTTP 403 on login due to auth change ? #38

sledgemhammer opened this issue Oct 1, 2023 · 16 comments

Comments

@sledgemhammer
Copy link

sledgemhammer commented Oct 1, 2023

Seems like Growatt implemented/updated something in the loginflow.
Since a couple of days a html 403 response with working credentials on the webpage

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init_.py", line 49, in login
return self.back_success_response(response)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 82, in _back_success_response
raise GrowattApiError("Request failed: %s" % response)
growatt.GrowattApiError: Request failed: <Response [403]>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_main
.py", line 9, in
api.login(username, password)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 51, in login
raise LoginError
growatt.LoginError

@sledgemhammer
Copy link
Author

sledgemhammer commented Oct 1, 2023

error codes adressing to different server url :

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init_.py", line 49, in login
return self.back_success_response(response)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 82, in _back_success_response
raise GrowattApiError("Request failed: %s" % response)
growatt.GrowattApiError: Request failed: <Response [405]>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_main
.py", line 9, in
api.login(username, password)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 51, in login
raise LoginError

@Nbondb
Copy link

Nbondb commented Oct 4, 2023

Looking at the SSL it looks like 2 new parameters are required on login.
NewLogin=1 - fixed
ipvcpc=. A string that changes each login, example 00000000-377a-d001-0000-0000000190e9.
I've no idea what this is.
It might be worth adding NewLogin=0 and seeing if that works?

@tulamidan
Copy link

Any suggestion how to fix that?

@Nbondb
Copy link

Nbondb commented Oct 7, 2023

I'm a beginner in python and have looked at code and tried to change, but no success. Really needs the original author or other expert to investigate.

@laqroix
Copy link

laqroix commented Oct 24, 2023

for me, 'NewLogin':1 parameter was enough to get the newTwoLoginAPI.do running, and from there other methods too. it looks like they change response format but at least it returns all values (i managed to get LoginAPI.do working, but it only returned plant status and 'data': {})

@Nbondb
Copy link

Nbondb commented Oct 27, 2023

Hi
My Shinephone app calls newTwoLoginAPIV2.do and has 'newLogin=1' that fails as does 'NewLogin=1'.
I've tried newTwoLoginAPI with 'newLogin' and 'NewLogin=1', both get 403.

Any chance you could send your bit of code (of course hiding user/password!)

@laqroix
Copy link

laqroix commented Oct 27, 2023

sure, login that works for me:

    def login(self, username, password, is_password_hashed=False):
        if not is_password_hashed:
            password = hash_password(password)

        response = self.session.post(self.get_url('newTwoLoginAPI.do'), data={
            'userName': username,
            'password': password,
            'NewLogin':1
        })
        # print (response.content)
        data = json.loads(response.content.decode('utf-8'))['back']
        if data['success']:
            data.update({
                'userId': data['user']['parentUserId'],
                'userLevel': data['user']['rightlevel']
            })
        return data

call:

api =  GrowattApi()
login_response = api.login(username, password)

@sledgemhammer
Copy link
Author

sledgemhammer commented Oct 28, 2023

sure, login that works for me:

When replaceing the code in original code in init_py with your code i get :

`Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init_.py", line 72, in login
result = self.back_success_response(response)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 159, in _back_success_response
raise GrowattApiError("Request failed: %s" % response)
growatt.GrowattApiError: Request failed: <Response [403]>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 193, in run_module_as_main
"main", mod_spec)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_main
.py", line 9, in
api.login(username, password)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\growatt_init
.py", line 78, in login
raise LoginError
growatt.LoginError`

did you change anything else ? ( i am using the growatt 0.0.4 package on windows )
And call it like : python.exe -I -m growatt USER PASSWORD wich used to work just fine

Any help to get it working again is very much appriciated....

@Nbondb
Copy link

Nbondb commented Oct 28, 2023

I've also struggled. First just getting the indentation correct! I now get the response as <b'error'>. (my brackets). Then
data = json.loads(response.content.decode('utf-8'))['back']
^^^^
NameError: name 'json' is not defined

Which is odd as json was in the original and worked. I'm using the latest example code from github on termux On Android phone. I only started this after growatt updated Shinephone.

@Nbondb
Copy link

Nbondb commented Oct 28, 2023

I've gone back to original code but added New login 1. I still get same 403 with newTwoLoginAPI And newTwoLoginAPIV2.
Code is
response = self.session.post(
self.get_url("newTwoLoginAPIV2.do"),
data={"userName": username, "password": password_md5, "New login": 1)

}
)
try:
result = self._back_success_response(>
self.logged_in = True
result["userId"] = result["user"]["id>
return result
except GrowattApiError:
raise LoginError

@laqroix
Copy link

laqroix commented Oct 30, 2023

its true that im connecting to 'https://server-api.growatt.com/', 'https://server.growatt.com/' gives me 403 too. i probably could make an merge request if i will fing some spare time...

@sledgemhammer
Copy link
Author

its true that im connecting to 'https://server-api.growatt.com/', 'https://server.growatt.com/' gives me 403 too. i probably could make an merge request if i will fing some spare time...

if i change def login and url from laqroix and i print the response then i get a new error 405
Sorry, your request has been blocked as it may cause potential threats to the server's security.

@laqroix : when editing the growatt 0.0.4 package i noticed that the use in your code for " and ' is different. So I suppose you use a different code or have changed more than only the suggested parts. Is that correct ?

I hope the original coder sjord will join to help us solve it ( with all the info laqroix is sharing , tnx!)
or someone that has a working situation is willing to share the complete code package so we are able to find the differences.

@laqroix
Copy link

laqroix commented Oct 30, 2023

yes a was modifying that code for some time, trying different urls, method versions, code snippets from different scripts etc. it was a pain to get it working...

@sledgemhammer
Copy link
Author

That makes sense,
At the moment i keep getting the WAF reply 405 where the web fire wall is not accepting my request, so not even reaching to the webserver

@Nbondb
Copy link

Nbondb commented Nov 1, 2023

I've tried using the Automate app on Android phone to call the http post (and I'll probably use it to develop my functionality if it works)
https://server-api.growatt.com:443/newTwoLoginAPIV2.do.
I get http status 200 success but the response returned is always
{"back":{"msg":"501","success":false,"error":"User Name Not Be Empty"}}
And any subsequent http call to the server returns http status 501 and a document saying "not logged in".
I've tried setting username and userName no difference.
I've tried newLogin=1 and NewLogin=1 no difference, indeed I get the same result setting it to 0 or leaving it out entirely.
So I have no idea what to do.

@Nbondb
Copy link

Nbondb commented Nov 15, 2023

Did you get this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants