0
我是python的新手,我想製作一個程序將命令發送到2960思科交換機並顯示回結果。Python 3 telnetlib「需要類似字節的對象」
我能夠與交換機建立連接並讓它顯示我的橫幅信息,但是一旦我嘗試輸入用戶名和密碼,一切就會順利進行。以下是錯誤消息我得到:
Traceback (most recent call last):
File "C:/Users/jb335574/Desktop/PythonLearning/Telnet/TelnetTest2.py", line 8, in <module>
tn.read_until("Username: ")
File "C:\Users\admin1\AppData\Local\Programs\Python\Python35-32\lib\telnetlib.py", line 302, in read_until
i = self.cookedq.find(match)
TypeError: a bytes-like object is required, not 'str'
這裏是我的代碼:
import telnetlib
un = "admin1"
pw = "password123"
tn = telnetlib.Telnet("172.16.1.206", "23")
tn.read_until("Username: ")
tn.write("admin1" + '\r\n')
tn.read_until("Password: ")
tn.write("password123" + '\r\n')
tn.write("show interface status" + '\r\n')
whathappened = tn.read_all()
print(whathappened)$