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

405 Client Error #74

Closed
gconceicao opened this issue Aug 23, 2023 · 98 comments · Fixed by #77
Closed

405 Client Error #74

gconceicao opened this issue Aug 23, 2023 · 98 comments · Fixed by #77

Comments

@gconceicao
Copy link

When I try to Login the error below is happing.

requests.exceptions.HTTPError: 405 Client Error: Not Allowed for url: https://server-api.growatt.com/newTwoLoginAPI.do

Someone with the same error?

@indykoning
Copy link
Owner

This may be because of previous requests getting your user agent blocked.
You can use another user agent or set it to generate random user agents
https://github.com/indykoning/PyPi_GrowattServer#initialisation

@gconceicao
Copy link
Author

It is already in Randon user ID.

self.api = growattServer.GrowattApi(add_random_user_id = True, agent_identifier =(GROWATTSERVER.GrowattApi.agent_identifier))

Dalvik/2.1.0 (Linux; U; Android 12; https://github.com/indykoning/PyPi_GrowattServer) - 21545

@hossein4214
Copy link

same error , random User-Agent doesnt work for me , any other solution?

@Derko01
Copy link

Derko01 commented Aug 24, 2023

See #73
This worked for me.

@gconceicao
Copy link
Author

Independent of the user agent, the error persist. @Derko01 Is it work now for your?

@Derko01
Copy link

Derko01 commented Aug 24, 2023

version: growattServer (1.4.0)
__init.py__: server_url = 'https://server.growatt.com/'
my own Python-script: api = growattServer.GrowattApi(False, "whatever")

And the above combination works for me.

@gconceicao
Copy link
Author

That is it.

The problem is that the Server was in server-api and not just server.

Thank you @Derko01

@hossein4214
Copy link

version: growattServer (1.4.0) __init.py__: server_url = 'https://server.growatt.com/' my own Python-script: api = growattServer.GrowattApi(False, "whatever")

And the above combination works for me.

That's Worked , thank you ^_^

@fridayowl
Copy link

@indykoning I hope this message finds you well. I am writing to report an issue I encountered while attempting to access the Growatt API via the following server URL: https://server-api.growatt.com/

Issue Details:

Server URL: https://server-api.growatt.com/
Error Encountered: ExceptionGrowatt.py exception at login 405 Client Error: Not Allowed for url: https://server-api.growatt.com/newTwoLoginAPI.do
Scenario:

When making a request to the endpoint "/newTwoLoginAPI.do" using the HTTP POST method, I am consistently met with a 405 error, indicating that the request is not allowed for the specified URL. This occurs even when I make the request without including any User-Agent in the header.

Further Observation:

In an attempt to address this, I added a random User-Agent to the request header. However, I encountered the same error message, indicating that the problem persisted.

Alternative API URL:

I also tried changing the API URL to https://server.growatt.com/. Unfortunately, this led to a different error. Specifically, upon attempting to log in, I received the following error: "No connection adapters were found for 'https://server.growatt.comnewtwologinapi.do/'."

@fridayowl
Copy link

@indykoning i tried using an npm library https://www.npmjs.com/package/growatt. -> This one was working for me .

@Sjord
Copy link

Sjord commented Aug 28, 2023

I also tried changing the API URL to https://server.growatt.com/. Unfortunately, this led to a different error. Specifically, upon attempting to log in, I received the following error: "No connection adapters were found for 'https://server.growatt.comnewtwologinapi.do/'."

This could be a result of omitting the final slash when configuring https://server.growatt.com/. I.e. you configured https://server.growatt.com instead of https://server.growatt.com/.

@fridayowl
Copy link

@Sjord import requests
import re

def authenticate (username , password ):
url = "https://server.growatt.com/login"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
'Connection': 'keep-alive'
}
data = {
'account': username,
'password': password,
'validateCode': ''
}

response = requests.post(url, headers=headers, data=data)
print(response.text)
cookies = response.headers.get('set-cookie')
print(cookies)
jsessionid_match = re.search(r'JSESSIONID=([^;]+)', cookies)
print(jsessionid_match)
if jsessionid_match:
        jsessionid = jsessionid_match.group(1)
        referer = f"https://server.growatt.com/index;jsessionid={jsessionid}"
print(referer)
return cookies , referer

def generation_get_data(asset):

auth = authenticate (asset["username"],asset["password"])
plantid= asset["plantid"]
url = f"https://server.growatt.com/panel/getDevicesByPlantList?plantId={plantid}&currPage=1"

payload = {}
headers = {
  'Cookie':auth[0],
  'Referer': auth[1]
}

response = requests.request("POST", url, headers=headers, data=payload)
return response.text

This works for me .

@mvdh02
Copy link

mvdh02 commented Sep 29, 2023

What do I have to change for example simple.py to get this working again? For a few days ago everything worked fine. But with a server update by Growatt this error occurred to me.

@muppet3000
Copy link
Contributor

Yeah, if anyone works out what change needs to be made to make things work again I'd love to see it.
I've noticed (from sniffing the traffic on my android phone) that it's making an additional login to oss.growatt.com now as well, but I can't see that making a difference.
I can't work out how to make this library work again.

@ryandrake182
Copy link

ryandrake182 commented Sep 30, 2023

+1 for the same issue.

Things I've tried:

  • modify server URL: server-api.growatt.com/ (405 Client Error Not Allowed for URL)
  • modify server URL: server.growatt.com/ - (403 Client Error: Forbidden for URL)
  • secure/unsecure connection: http & https for URL (no change, same error as above)
  • different user-agents: (iPhone, Chrome for Windows, Safari for MacOS) (no change same error as above)
  • random user agent using growattServer.GrowattApi(True) (no change same error as above).
  • Creating a new growatt user account on my main account and using those credentials instead

Doing some quick google research it seems other libraries for pulling Growatt data are also having the same issue

Hopefully this helps someone with a bit more experience with python to fix the issue

@indykoning
Copy link
Owner

Yeah i'm getting errors trying to get my data from Growatt as well.
At the same time i cannot use the shinephone app either to log in.
It seems Growatt have tried to add certain security measures like bot detection which are backfiring.
You cannot do bot detection on an API endpoint since the only things using it are going to be bots.

I do hope they fix it soon, i'm afraid we're out of user-friendly ways to get Growatt data otherwise...

This is great information though thank you!

Things I've tried:

  • modify server URL: server-api.growatt.com/ (405 Client Error Not Allowed for URL)
  • modify server URL: server.growatt.com/ - (403 Client Error: Forbidden for URL)
  • secure/unsecure connection: http & https for URL (no change, same error as above)
  • different user-agents: (iPhone, Chrome for Windows, Safari for MacOS) (no change same error as above)
  • random user agent using growattServer.GrowattApi(True) (no change same error as above).
  • Creating a new growatt user account on my main account and using those credentials instead

Doing some quick google research it seems other libraries for pulling Growatt data are also having the same issue

Hopefully this helps someone with a bit more experience with python to fix the issue

To add to this, and why i believe it's Growatt messing up bot detection:
home-assistant/core#100874 (comment)
image
image
when navigating to server-api.growatt.com by browser

@ryandrake182
Copy link

@indykoning You're welcome, I tried to figure it out but got nowhere, I'm not much of a developer though 🤣

For what it's worth, for me the ShinePhone app is working, although I'm on iOS. It may be that just the android app is having issue but sadly I don't have an android device to test with.

From your screenshot I would agree their WAF is incorrectly configured, it might be that they fix this in a few days when they realise the android app is broken. I will try to raise issue of the broken android app with their support in the hopes they fix their side!

@APKing1
Copy link

APKing1 commented Oct 2, 2023

FYI - ShinePhone App working fine on my Android devices right now.

@Sweenylein
Copy link

Sweenylein commented Oct 2, 2023

Growatt has just released a ShineApp update for the iPhone. Optimise Login Logic

I think there was a server change, the apps had to be adjusted.

The third-party systems are excluded for now.

@vtraveller
Copy link

vtraveller commented Oct 2, 2023

ah @indykoning - you found my home-assistant/core#100874 (comment)

FWIW I think that the newTwoLoginAPI.do has been expanded out.

view-source:https://server.growatt.com/login in the login2() function. I'm not sure there's a radical change in the behaviour of the backend. The main login page files have just been rejigged.

I'm kinda busy in the week, so I've not really had the time to deep dive, but my investigations were going to centralize on that, as I think there just needs to be a tweak in this repo around init.py:131 to work against the new server code.

@gconceicao
Copy link
Author

gconceicao commented Oct 5, 2023

It is seem that login url change and cookies is a input as well.

POST /newTwoLoginAPIV2.do HTTP/1.1
Cookie: acw_tc="0bc1a08716965472817346460e7c421aad93a714ec95ecddfb1c9dd7797124";$Path="/";$Domain="server-api.growatt.com"; JSESSIONID=01F3E0091E4D2EA4FB278D6316E69F4D; assToken=bececd42fc2f24fda063343e48caac61; SERVERID=f3dd01374e65b00d703f65f037a1144c|1696548335|1696548333
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 335
User-Agent: Dalvik/2.1.0 (Linux; U; Android 13; M2102J20SG Build/TKQ1.221013.002)
Host: server-api.growatt.com
Connection: Keep-Alive
Accept-Encoding: gzip

@vtraveller
Copy link

It is seem that login url change and cookies is a input as well.

POST /newTwoLoginAPIV2.do HTTP/1.1

Cookie: acw_tc="0bc1a08716965472817346460e7c421aad93a714ec95ecddfb1c9dd7797124";$Path="/";$Domain="server-api.growatt.com"; JSESSIONID=01F3E0091E4D2EA4FB278D6316E69F4D; assToken=bececd42fc2f24fda063343e48caac61; SERVERID=f3dd01374e65b00d703f65f037a1144c|1696548335|1696548333

Content-Type: application/x-www-form-urlencoded;charset=UTF-8

Content-Length: 335

User-Agent: Dalvik/2.1.0 (Linux; U; Android 13; M2102J20SG Build/TKQ1.221013.002)

Host: server-api.growatt.com

Connection: Keep-Alive

Accept-Encoding: gzip

Yes. That was my conclusion too. My starting point for fixing this was to walk the web version. I think the Android app was using the same services and they all got rejigged.

You can see from the website this isn't a well honed code base but a simple series of hacked up files meeting various product needs.

The changes seem to have moved code, but also added support for some unreleased EV charger product, which has its own server to access data from.

I don't think it's impossible to fix. Just that the new code needs to be unfurled. I was going to look at the WayBackMachine to see what was in the original /newTwoLoginAPIV2.do file, so I can piece it all back together.

@ghost
Copy link

ghost commented Oct 6, 2023

If you could fix it that would be absolutely brilliant. The sole purpose of my Home Assistant installation is to link my Growatt system to my immersion (hot water tank) heater. I am not able to use Grott as my installer monitors my system and after checking with them they say that any alteration of the WiFi dongle will invalidate my service agreement.

@muppet3000
Copy link
Contributor

I'm really interested in a fix for this, mainly because I spent a few hours the other night looking at the new API and the netSSL output etc and I've made a carbon copy of what the app does and I still get the error so I can't work out what it does!

@Sweenylein
Copy link

Sweenylein commented Oct 6, 2023

@muppet3000

Did you try this? 35d50c4

@muppet3000
Copy link
Contributor

@muppet3000

Did you try this? 35d50c4

No, I was exclusively trying to replicate the behaviour of the app.
Does that change work?

@Sweenylein
Copy link

@muppet3000

For the registration via https://server.growatt.com/login I get - reproduced in Postman - at least once {"result":1} and PlantID etc. back. However, I do not manage to retrieve any more data.

Step 1: https://server.growatt.com/login?account=xxxx&passwordCrc=yyyy&login_type="web"
with User-Agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.81"

@ghost
Copy link

ghost commented Oct 10, 2023

@JansonBHong

Many many thanks

Updated repo with example, helpers, and minor bug fixes.

Many many thanks - I will take a look later

@vtraveller
Copy link

Android app, and chrome browser to server.growatt.com both work fine on the phone.

Then the answer is simple. Run the Inspector, turn off page clearing. Log in, and then replay what it did in its POSTs.

@vtraveller
Copy link

Oh wait. I thought you wanted to all get to server-api.growatt.com. You gave the impression it was specifically needed.

@muppet3000
Copy link
Contributor

muppet3000 commented Oct 10, 2023

Oh wait. I thought you wanted to all get to server-api.growatt.com. You gave the impression it was specifically needed.

I'm referring to server-api.growatt.com, that's what the android app uses.
No problem signing into the app, no problem signing into server.growatt.com from my network, the specific problem I am trying to resolve is the login to the new URL.
I'll post a screengrab here, but I'll need to redact certain things.
If you're keen to collaborate on a potential fix @vtraveller just drop me an email and I'll hook you up with some screengrabs and un-redacted user account to reproduce and test.

image

When I do a full signout of the app and then sign back in, there's a few other sites it reaches out to for login, but I'm not sure if they're essential or not.
Happy to share full captures for NetCapture privately.

@ghost
Copy link

ghost commented Oct 10, 2023

@JansonBHong

Many many thanks

Updated repo with example, helpers, and minor bug fixes.

Many many thanks - I will take a look later

Hi - sorry to bother you yet again. If I run the latest gotest.py it returns my plant ID, the device SN and the DataLoger serial number. It then fails with the following error

highlevel test
Traceback (most recent call last):
File "/home/pi/gowatt-main/gotest.py", line 41, in
pCharge = session.getBatteryChargeRate()
File "/home/pi/gowatt-main/gowatt.py", line 269, in getBatteryChargeRate
charge = float(device['chargePower']) * 1000
TypeError: 'NoneType' object is not subscriptable

@vtraveller
Copy link

This is a good example of the type of problem you hit with these fluxy POSTs from the growatt servers.

You should check the return variable device like this:

device = self.rawGetSPAstatusData()
print(str(device)

You'll then know if your data values match mine from the server. I'm guessing they don't.

Later I'll post a document I build of all the JSON I could find. Then at least people can compare responses.

@pro-sumer
Copy link

@vtraveller Thank you for the work you have done on this!

I think I can now get all the data again that I need to fix my iOS shortcut to display a graph in a widget.

However, I could not find one more parameter that we need for fixing the Growatt integration in the Homey SolarPanels App. Were you able to get the "Current Power (in W)"? If so, with which API call?

@vtraveller
Copy link

Ah. Maybe. A lot of the units have switched to kWh and show with a decimal.

If you look at getStatusData you'll see ppv, ChargePower, pdisCharge1 grid etc

Multiply all by 1000 and then use simple maths if a value is missing.

@APKing1
Copy link

APKing1 commented Oct 11, 2023

@JansonBHong

Many many thanks

Updated repo with example, helpers, and minor bug fixes.

Thank you. Very helpful.

@djmastertgv
Copy link

Hello,
Running the example in python 3.8/3.10/3.11 give me the error: "AttributeError: module 'gowatt' has no attribute 'Gowatt'".
Cand anyone tell me what i'm doing wrong?
Thank you.

@rodrigomenna
Copy link

@J4CE2

sim, servidor.growatt.com

Lá em energia, gerenciamento de planta, ferramentas operacionais você pode enviar uma chave (Compartilhar) por e-mail.

Hello dear, I've completed the procedure to receive the key/URL via email. I validated the access through a browser, and it worked. So, how can I integrate this with Home Assistant to access the measurements?

@J4CE2
Copy link

J4CE2 commented Oct 27, 2023

@muppet3000 - I just noticed 3 days ago the API started working again, I guess they have changed something once more.

@muppet3000
Copy link
Contributor

@muppet3000 - I just noticed 3 days ago the API started working again, I guess they have changed something once more.

If that's the case, that's pretty cool. I'm currently on holiday but I'll test when I'm back next week.

@muppet3000
Copy link
Contributor

This URL: https://openapi.growatt.com/ appears to work (for now)

@gconceicao
Copy link
Author

@muppet3000 Do you already test this openapi with the application?

I am trying to do it, but without success.

@muppet3000
Copy link
Contributor

It worked the other day, I haven't checked since last week though.

@marcovtwout
Copy link
Contributor

marcovtwout commented Nov 29, 2023

I tested the following URLs today (from The Netherlands):

In all cases I tested the results are the same regardless of the request method (this API, a web browser, different user agent or IP). I guess once the WAF decides a certain type of request or endpoint is getting suspicious traffic, it blocks a lot more traffic from that point on. In order to attempt to mitigate future blocks it might be handy to check the documentation and understand how the WAF works: https://www.alibabacloud.com/help/en/web-application-firewall

Changing the default url to https://openapi.growatt.com/ or https://server.growatt.com/ (maybe more unreliable, see home-assistant/core#103858 (comment)) seems like an acceptable workaround for the time being.

@fisken
Copy link

fisken commented Nov 29, 2023

maybe I'm misunderstand and just need to edit the init.py. but shouldn't I be able to change the server url with this in my code?

api.server_url = "https://openapi.growatt.com"

@Saentist
Copy link

https://www.showdoc.com.cn/262556420217021/1494055033077450
official changelog in documentation do not say that is changed logging type,
but say to use TOKEN
https://www.showdoc.com.cn/262556420217021/1494053950115877

@marcovtwout
Copy link
Contributor

@fisken This library just sets the default value, you can set it here or in your own code. Note that the trailing slash is required.
@Saentist That looks like another Growatt API that is not used by this library.

@Saentist
Copy link

@marcovtwout This is official Growatt WEB API regularly updated.
There is a Inverter and battery by type settings etc.

@patcher-ms
Copy link

@Saentist I was looking into that API but I cannot figure out where to get the API token form. Do you know how I could get it?

@Saentist
Copy link

@patcher-ms before token can be seen in https://server.growatt.com in Settings > Account Management
where is now API Secret Key token

now in https://oss.growatt.com with is not possible for self installed systems

@marcovtwout
Copy link
Contributor

@Saentist Thats really nice and could mean the way forward, but I suggest to create a seperate issue/feature request for this to keep things on topic.

@marcovtwout
Copy link
Contributor

Just FYI, the updated URL still works after 2+ months of testing: #74 (comment)

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

Successfully merging a pull request may close this issue.