Salamek / huawei-lte-api

API For huawei LAN/WAN LTE Modems
GNU Lesser General Public License v3.0
350 stars 87 forks source link

huawei_lte_api.exceptions.ResponseErrorException: 9003: Unknown #211

Open LaurentMarsan opened 2 months ago

LaurentMarsan commented 2 months ago

Discussed in https://github.com/Salamek/huawei-lte-api/discussions/208

Originally posted by **LaurentMarsan** April 20, 2024 Hello Just installed your lib, I'm trying to simply switch wifi on/off. When switching on, everything ok (I red that you made it such a way to do nothing if already enabled), but when switching off, I get: ```py Traceback (most recent call last): File "setWifi.py", line 29, in setWifi(0) File "setWifi.py", line 21, in setWifi if client.wlan.wifi_network_switch(val) == ResponseEnum.OK.value: File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/api/WLan.py", line 255, in wifi_network_switch return self.save_wlan_settings(items) File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/api/WLan.py", line 243, in save_wlan_settings return self.set_multi_basic_settings([item.to_dict() for item in settings]) File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/api/WLan.py", line 112, in set_multi_basic_settings 'WifiRestart': 1 File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/Session.py", line 215, in post_set self._post(endpoint, data, refresh_csrf, prefix, is_encrypted, is_json) File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/Session.py", line 34, in wrapped return fn(*args, **kw) File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/Session.py", line 254, in _post response_data = cast(str, self._check_response_status(self._process_response_data(response))) File "/home/pi/.local/lib/python3.7/site-packages/huawei_lte_api/Session.py", line 158, in _check_response_status error_code huawei_lte_api.exceptions.ResponseErrorException: 9003: Unknown ``` Any idea? Something I made wrong? Hardware is b525s-23a, btw.

Code used is

from huawei_lte_api.Connection import Connection
from huawei_lte_api.Client import Client
from huawei_lte_api.enums.client import ResponseEnum
from time import sleep

def setWifi(val):
    with Connection("http://192.168.8.1", username="admin", password="XXXXXXXXXXXXXXX") as connection:
        client = Client(connection)
        if client.wlan.wifi_network_switch(val) == ResponseEnum.OK.value:
            print('Wi-Fi was toggled successfully')
            return True
        else:
            print('Error')
            return False

if __name__=="__main__":
    setWifi(False)
    sleep(30)
    setWifi(True)
Salamek commented 1 month ago

Sorry i was not able to reproduce your issue on my B310s-22... you need to hunt this bug down on your own... Check what request your webUI is making to the router in your browser dev tools -> network tab and compare that request to the request that huawei-lte-api is doing, see what is different and try to get it working. (I can't fix what i can't reproduce)

LaurentMarsan commented 4 weeks ago

Thanks for your answer. I'm ok for a bug hunt, but I'm not an expert at all. Could you please/ 1/ give more details about the dev tool I should use (on Firefox, for instance)? 2/ which request should I try in my browser? 3/ how to compare this browser request to the request from huawei-lte-api?

Salamek commented 4 weeks ago

Hmm, it text i have provided in previous response did not help much... i think it will be better if you just dump the POST request for enable/disable. See this video on how to do that and send me both files (on my email that is in my github profile, one for disable POST request other for enable POST request). I'll do the rest.