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())
私は何十もの異なる文字列の組み合わせを試してみました。スペルを前後に追加しようとしましたが、スペースを期待するためには何もしませんでしたが、最初のコマンド。前の他の3つの文字列は、うまく読めました。このread_untilに代わるものは何ですか?PythonでTelnetlibのread_untilが期待される文字列を読み込まない。代替案とは何ですか?
また、私はsleep(.5)とsleep(1)を試しましたが、どちらもうまくいきませんでした。私はread_untilを待たずにバッファに文字列を書き込もうとしました。助けて!