import getpass
import sys
import telnetlib
host = "10.28.103.126"
user = b"apc"
password = b"apc"
outlet = b"8"
tnObject = telnetlib.Telnet(host)
print("yes")
tnObject.read_until(b"User Name :")
tnObject.write(user + b"\n")
print("sent user")
tnObject.read_until(b" ")
tnObject.write(password + b"\n")
print("sent password")
tnObject.read_until(b"Name ")
tnObject.write(b"1" + b"\n")
print("sent first command")
tnObject.read_until(b">")
tnObject.write(outlet + b"\n")
print("sent second command")
tnObject.read_until(b">")
tnObject.write(b"1" + b"\n")
print("sent third command")
tnObject.read_until(b">")
tnObject.write(b"2" + b"\n") #(1 is ON) (2 is OFF)
print("sent fourth command")
tnObject.read_until(b"Enter ")
tnObject.write(b"yes" + b"\n" + b"\n")
tnObject.read_until(b">")
tnObject.close()
print(tnObject.read_all())
我已經嘗試了數十種不同的字符串組合,應該閱讀,我嘗試在前後添加空格,拼寫和簡單的b「」來期待空間,但似乎沒有任何工作發送第一個命令。之前的其他3個字符串被讀取得很好。什麼是這個read_until的替代方案?在Python中,Telnetlib的read_until不會讀取預期的字符串。什麼是替代品?
此外,我已經嘗試睡眠(.5)和睡眠(1),但也沒有工作。我也嘗試了在不等待read_until的情況下將字符串寫入緩衝區。幫幫我!