iMicknl / python-sagemcom-api

(Unofficial) Python wrapper to interact with SagemCom F@st routers via internal API's.
MIT License
83 stars 36 forks source link

F@st 5670 ServerDisconnectedError while get DeviceInfo #340

Closed h00t2y closed 1 month ago

h00t2y commented 1 month ago

Model information

Key Value
Model name F5670v2
Hardware Version 3.0
Software Version v19.1.164.16.14.3

I use SHA512 hashing. Tried on 3 different debian with python 3.7.3 and 3.9.3 as well.

Describe the bug

The python script fails with error : aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected It happens when the script runs Device/DeviceInfo command.

I can see from the router's log that login was successfull. Please find attached log of tree values.

What could be my problem? sagemcom5670valuestree.txt

[bug]

h00t2y commented 1 month ago

Made some changes according to #252 In client.py: instead: connector=TCPConnector(ssl=verify_ssl), connector=TCPConnector(ssl=verify_ssl, force_close=True),

And i add: await asyncio.sleep(0.1) before: async with self.session.post(......

Now with this: device_info = await client.get_device_info() print(f"{device_info.id} {device_info.model_name}") Output: 88:0F:A2:55:24:48 Fast5670AXv2

hosts and xpath commands are working as well now :)

iMicknl commented 1 month ago

@h00t2y have you tried the latest version of the package? We can see if we can include these fixes to the package.

h00t2y commented 1 month ago

Oh. I was on 1.0.5. :) 1.3.2 just worx! THX Could U help me with logout? What should be the correct lines to logout in my test.py?

iMicknl commented 1 month ago

Just await client.logout().

h00t2y commented 1 month ago

That was the first i tried but unf i got: AC:6F:BB:2E:90:E8 - AC:6F:BB:2E:90:E8 EC:FA:BC:06:59:E1 - HAA-0659E1 Traceback (most recent call last): File "/home/pi/sagem.py", line 35, in asyncio.run(main()) File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/home/pi/sagem.py", line 33, in main await client.logout() File "/home/pi/.local/lib/python3.9/site-packages/sagemcom_api/client.py", line 342, in logout await self.__api_request_async([actions], False) File "/home/pi/.local/lib/python3.9/site-packages/sagemcom_api/client.py", line 286, in api_request_async result = await self.post(api_host, form_data) File "/home/pi/.local/lib/python3.9/site-packages/backoff/_async.py", line 151, in retry ret = await target(*args, **kwargs) File "/home/pi/.local/lib/python3.9/site-packages/sagemcom_api/client.py", line 229, in __post raise InvalidSessionException(error) sagemcom_api.exceptions.InvalidSessionException: {'code': 16777219, 'description': 'XMO_INVALID_SESSION_ERR'}

After listing the first two devices got this error. If i have the line "reutrn" after "await client.logout()" got no error but still only lists the first two devices.

My test py:

import asyncio from sagemcom_api.client import SagemcomClient from sagemcom_api.enums import EncryptionMethod from sagemcom_api.exceptions import NonWritableParameterException

HOST = "192.168.1.1" USERNAME = "" PASSWORD = "" ENCRYPTION_METHOD = EncryptionMethod.SHA512

async def main() -> None: async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client: try: await client.login() except Exception as exception: # pylint: disable=broad-except print(exception) return

devices = await client.get_hosts()

for device in devices: if device.active: print(f"{device.id} - {device.name}")

await client.logout() asyncio.run(main())

h00t2y commented 1 month ago

Nevermind. It was some typo.

async def main() -> None: async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD) as client: try: await client.login() except Exception as exception:
print(exception) return

    devices = await client.get_hosts()

    for device in devices:
        if device.active:
            print(f"{device.id} - {device.name}")

    await client.logout()

asyncio.run(main())

Now it worx! thx