[Python] Cannot properly interact with telnet devices with newer telnetlib modules in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I've used the telnetlib module in Python and some of you may know that it is deprecated as of Python version 3.13. While I understand that telnet is an old and perhaps archaic interface, there are still devices in presence today that use that protocol and in my case, they did not even bother with setting up a proper login shell. Sometimes it is not needed when it is set up to be managed internally in a hardware setup. The protocol of this device is very simplistic, you usually send "two byte" commands with some params without spaces and generally get very short responses while part of them is an echoing back what you just typed in.

    When I first attempted it with Exscript, I was successful but then the connection hanged and I had to restart the kernel to get it working again. The now maintained telnetlib3 requires management through asyncio which is hard for me to understand and manage.

    One problem I have with the device is that it is very delicate. If I do read_all() it just hangs or does time_out without even retrieving any data. The command read_very_eager() makes it possible to read out data and it behaves as I want to. If I run that command, it returns the output of the last command and empties the buffer. If I run it when nothing has come out it returns b'' without hanging or freezing and I can manage that output.

    But when I move to telnetlib3, what is the corresponding command there? None of the commands in this page do what the telnetlib command does:

    https://telnetlib3.readthedocs.io/en/latest/api/stream_reader.html

    Continue reading...

Compartilhe esta Página