sincze / Domoticz-Growatt-Webserver-Plugin

16 stars 10 forks source link

'back' in apiResponse without 'data' or 'plantId' #33

Closed JoostDkr closed 1 year ago

JoostDkr commented 1 year ago

Sometimes I got a Phython-error in the log on line: self.plantId = apiResponse["back"]["data"][0]["plantId"] the cause was: the apiResponse contail a 'back' element but no "data" or "plantId".

In order to prevent this Phython-error, I changed the line " if ('back' in apiResponse):" in "if ('back' in apiResponse and strData.find('data') > -1 and strData.find('plantId') > -1):"

Now i do not receive a Phyton-error any more, instead of that I got last night a proper exeption: Not received anything usefull!: {"back":"503","succes":false}}

sincze commented 1 year ago

Thanks for your insights. So just 1 line change and we are good to go?

OLD:

   try:
                if ('back' in apiResponse):              
                #if not ['back']['success']:
                #    Domoticz.Log("Login Failed")
                #elif ('back' in apiResponse):       

NEW:

   try:
                if ('back' in apiResponse and strData.find('data') > -1 and strData.find('plantId') > -1):
                #if not ['back']['success']:
                #    Domoticz.Log("Login Failed")
                #elif ('back' in apiResponse):                  
JoostDkr commented 1 year ago

Yep!