1

I am trying to make the Python Telnetlib to work with a PDU41001 switched power bar. I previously tried to interact with the device via putty using telnet and it works fine.

In my code, I'm able to connect to the device successfully as the code raise an exception if I change the IP address or the port, but there doesn't seem to be any output from the device whatsoever. Sending carriage returns doesn't seem to change anything. I'm out of ideas and I have no idea if it is an issue with the device, with the lib or with my code.

Here's the function I'm using to connect to the device. I tried to add delays to test if there was an issue with timing but it doesn't seem to change anything. I'm using VSCode to debug and validate input data from the device.

    def connect(self):
        """
        Establish a telnet connection with credentials
        """
        self.ping_ip_address(self.connection["host"])
        self.telnet_socket = telnetlib.Telnet()
        self.telnet_socket.open(host=self.connection["host"], port=self.connection["port"])
        time.sleep(1)
        response = self.telnet_socket.read_until('Login Name: ', timeout=2)
        self.telnet_socket.write(self.credentials["user"] + "\r")
        time.sleep(1)
        response = self.telnet_socket.read_until('Login Password: ', timeout=2)
        self.telnet_socket.write(self.credentials["password"] + "\r")
        response = self.telnet_socket.read_until('Welcome Administrator!', timeout=TELNET_RESPONSE_TIMEOUT)
X. Mercure
  • 39
  • 2

0 Answers0