import telnetlib def check_input_error(): tn = telnetlib.Telnet("10.209.10.111", 2168) tn.write("/\r\n".encode('ascii')) for _ in range(3): output = tn.read_until(b"Input error", timeout=3).decode('ascii') print(output) if "Input error" in output: return True return False result = check_input_error() print(result)