我正在修改一个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: expected an object with the buffer interface“任何见解都会有帮助。
发布于 2010-03-06 14:30:44
根据the docs,read_until的规格是(引用,我强调):
在遇到预期的给定字节字符串之前进行
读取
在Python3中,您没有传递字节的字符串,例如:
tn.read_until("User Name: ")相反,您将传递一个Unicode 字符串,在Python3中,这意味着一个字符串。
因此,将其更改为
tn.read_until(b"User Name: ")b"..."表单是指定文字字节字符串的一种方法。
(当然,其他类似的调用也是如此)。
https://stackoverflow.com/questions/2388414
复制相似问题