diff --git a/README.md b/README.md index df92f04..1ae44fa 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The Sagemcom F@st series is used by multiple cable companies, where some cable c | --------------------- | -------------------- | --------------------- | ----------------------------- | | Sagemcom F@st 3864 | Optus | sha512 | username: guest, password: "" | | Sagemcom F@st 3865b | Proximus (b-box3) | md5 | | -| Sagemcom F@st 3890V3 | Delta / Zeelandnet | md5 | | +| Sagemcom F@st 3890V3 | Delta / Zeelandnet | sha512 | | | Sagemcom F@st 3896 | | sha512 | username: admin | | Sagemcom F@st 4360Air | KPN | md5 | | | Sagemcom F@st 4353 | Belong Gateway | md5 | username: admin, password: "" | @@ -50,13 +50,14 @@ The following script can be used as a quickstart. ```python import asyncio -from sagemcom_api.enums import EncryptionMethod from sagemcom_api.client import SagemcomClient +from sagemcom_api.enums import EncryptionMethod +from sagemcom_api.exceptions import NonWritableParameterException HOST = "" USERNAME = "" PASSWORD = "" -ENCRYPTION_METHOD = EncryptionMethod.MD5 # or EncryptionMethod.SHA512 +ENCRYPTION_METHOD = EncryptionMethod.SHA512 # or EncryptionMethod.MD5 async def main() -> None: async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client: @@ -81,8 +82,13 @@ async def main() -> None: custom_command_output = await client.get_value_by_xpath("Device/UserInterface/AdvancedMode") print(custom_command_output) - # Set value via XPath notation - custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true") + # Set value via XPath notation and catch specific errors + try: + custom_command_output = await client.set_value_by_xpath("Device/UserInterface/AdvancedMode", "true") + except NonWritableParameterException as exception: # pylint: disable=broad-except + print("Not allowed to set AdvancedMode parameter on your device.") + return + print(custom_command_output) asyncio.run(main()) diff --git a/sagemcom_api/client.py b/sagemcom_api/client.py index 89d6192..331578a 100644 --- a/sagemcom_api/client.py +++ b/sagemcom_api/client.py @@ -189,9 +189,9 @@ async def __api_request_async(self, actions, priority=False): } } - async with self.session.post( - api_host, data="req=" + json.dumps(payload, separators=(",", ":")) - ) as response: + form_data = {"req": json.dumps(payload, separators=(",", ":"))} + + async with self.session.post(api_host, data=form_data) as response: if response.status == 400: result = await response.text() raise BadRequestException(result) @@ -245,6 +245,7 @@ async def __api_request_async(self, actions, priority=False): async def login(self): """TODO.""" actions = { + "id": 0, "method": "logIn", "parameters": { "user": self.username,