我正在修改一个python脚本,通过telnet对一整个交换机进行更改:
import getpass
import sys
import telnetlib
HOST = "192.168.1.1"
user = input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("User Name: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("?\n")
tn.write("exit\n")
当脚本执行时,我收到一个“TypeError:期望一个带缓冲接口的对象”任何见解都会有所帮助。
答案 0 :(得分:2)
符合the docs,read_until
的规格(引用,我的重点):
读取直到给定的字节字符串, 预期,遇到了
你没有在Python 3中传递字节字符串,例如:
tn.read_until("User Name: ")
相反,您传递的是 text 字符串,在Python 3中表示Unicode字符串。
所以,将其更改为
tn.read_until(b"User Name: ")
b"..."
表单是指定文字字节字符串的一种方法。
(当然,与其他此类电话类似)。