0

I am trying to use python 3.10.9 on windows to create a telnet session using telnetlib, but I have trouble to read the complete response.

I create a telnet session like

session = telnetlib.Telnet(host, port, timeout)

and then I write a command like

session.write(command + b"\n")

and then I wait some really long time (like 5 seconds) before I try to read the response using

session.read_some()

but I only get half of the response back!

The complete response is e.g.

Invalid arguments

Usage: $IMU,START,<SAMPLING_RATE>,<OUTPUT_RATE>
  where SAMPLING_RATE = [1 : 1000] in Hz
        OUTPUT_RATE   = [1 : SAMPLING_RATE] in Hz

but all I read is the following:

b'\x1b[0GInvalid arguments\r\n\r\nUsage: $IMU,START,<'

More than half of the response is missing! How to read the complete response in a non-blocking way?

Other strange read methods:

  • read_all: blocking
  • read_eager: same issue
  • read_very_eager: sometimes works, sometimes not. Seems to contain a repetition of the message ...
  • read_lazy: does not read anything
  • read_very_lazy: does not read anything

I have not the slightest idea what all these different read methods are for. The documentation is not helping at all.

But read_very_eager seems to work sometimes. But sometimes I get a response like

F
FI
FIL
FILT
FILTE
FILTER

and so on. But I am reading only once, not adding the output myself!

Maybe there is a more simple-to-use module I can use instead if telnetlib?

Alex
  • 41,580
  • 88
  • 260
  • 469

1 Answers1

0

Have you tried read_all(), or any of the other read_* options available?

Available functions here.

JustLearning
  • 1,435
  • 1
  • 1
  • 9