python-sagemcom-api
python-sagemcom-api copied to clipboard
Sagemcom F@st 5655V2 Telekom support
Model information
| Key | Value |
|---|---|
| Model name | F@st 5655V2 |
| Hardware Version | 1.0 |
| Software Version | SG3G10000636 |
Describe the bug
Doesn't seem to work, using the sample code on the main GH page. An exception is caught in the async with SagemcomClient function that only prints the text 'id'. MD5 auth method is used, SHA512 times out.
To Reproduce
Steps to reproduce the behavior:
Run the "long" sample code on https://github.com/iMicknl/python-sagemcom-api
Expected behavior
It runs and prints stuff in the router.
Screenshots
N/A
Additional context
N/A
Could you share the full error message you get?
@iMicknl do you think it can be fixed? How can I provide more info for you? I started looking at some payloads and by eyeballing, they look OK, but must miss some fields or maybe they're not in an arrangement that's sufficient for this FW variant.
@kobuki are you familiar with Python yourselves? I don't have time currently to work on this, and it is especially hard to debug your router from here.
You could start with a debugger in VSCode, or just by putting print statements in the code. It would be good if you better understand the payload and where it is probably not parsing the payload correctly. The output you have shown above doesn't tell me anything unfortunately. It is weird that an exception is thrown with only the text 'id'. Best is to print the whole response there.
@iMicknl sure, I'll dig into a bit more, but I'd appreciate some hints, based on the stack trace and the response below if your time allows.
response after login:
[{'uid': 1, 'result': {'code': 16777238, 'description': 'Applied'}, 'xpath': 'Device', 'parameters': {'id': 1749808533, 'nonce': '2795251014'}}]
Traceback (most recent call last):
File "sagemcom.py", line 57, in <module>
asyncio.run(main())
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "sagemcom.py", line 27, in main
device_info = await client.get_device_info()
File "/usr/local/lib/python3.7/dist-packages/sagemcom_api/client.py", line 344, in get_device_info
data = await self.get_value_by_xpath("Device/DeviceInfo")
File "/usr/local/lib/python3.7/dist-packages/sagemcom_api/client.py", line 314, in get_value_by_xpath
response = await self.__api_request_async([actions], False)
File "/usr/local/lib/python3.7/dist-packages/sagemcom_api/client.py", line 204, in __api_request_async
api_host, data="req=" + json.dumps(payload, separators=(",", ":"))
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 1117, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 544, in _request
await resp.start(conn)
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client_reqrep.py", line 890, in start
message, payload = await self._protocol.read() # type: ignore
File "/usr/local/lib/python3.7/dist-packages/aiohttp/streams.py", line 604, in read
await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected
So it seems the response is correct, but some other connection problem prevents the code to go further. It's either a genuine disconnect, or some other expectation in network code that fails.
@kobuki I am using a Telekom router as well.
you may need to increase the timeout try this:
from aiohttp import ClientSession, ClientTimeout
...
async def main() -> None:
session = ClientSession(timeout=ClientTimeout(15))
async with SagemcomClient(HOST, USERNAME, PASSWORD, ENCRYPTION_METHOD, session=session) as client:
...
ServerDisconnectedError is instantaneous, I don't need to wait for it to appear, so I think it's not the timeout.
I have the same problem with the official Proximus BBox3. Only a text 'id' is printed. Did you solved it ?
The reason for "aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected" is because you are sending requests too fast. Just put 0.5s between requests and the problem will be solved.
In my case it's on the first call, so no subsequent ones to repeat too fast.
There are two independed problems here: The first one is that I wrote - when you send requests too fast, then it will end on ServerDisconnectedError exception. When this happens your session will stay logged on server and the second login attempt will end with 'id' Exception (and you need to wait couple of minutes in order to session expire). The reason is, that telecom firmware doesn't return XMO_* error descriptions but English translations. Just replace XMO_REQUEST_ACTION_ERR in const.py with 'Action error' and you will see the real login error reason. Try the example shown in readme, but add 'await asyncio.sleep(1)' before every client.* call. It will work. Tested on Sagemcom from Telecom Slovakia.
Sleeping between requests really helped in my case. Thank you very much!