Python - telnet - automation APC PDU

喜夏-厌秋 提交于 2019-12-19 11:34:21

问题


I am attempting to automation turning off connected devices to an APC PDU using python's built in telnet functionality. I believe I am able to enter in the username and password, but I cannot proceed after that. My code is as follows:

    telnet_session = telnetlib.Telnet(host=self.apc_ip)
    self.logger.info("Entering APC Username")
    telnet_session.read_until("User Name :")
    telnet_session.write(self.apc_username + "\n")
    self.logger.info("Entering APC Password")
    telnet_session.read_until("Password  :")
    telnet_session.write(self.apc_password + "\n")
    sleep(2)
    print telnet_session.read_all()

I'm running windows so I believe that https://github.com/quackenbush/APC is not an option as I cannot install pexpect.

Any help would be appreciated.

Thanks,

Parth


回答1:


The issue was I wasn't sending the correct end line.

In windows it's \r\n, not \n



来源:https://stackoverflow.com/questions/10306410/python-telnet-automation-apc-pdu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!