私は基本的には、ポート10001上のリモートTelnetサーバーからいくつかのデータを解析するPythonスクリプトを書いていますが一致しないtelnetlibのread_until()は、何
私は、次の(リターンを打つための'\n'
スタンド)のようなコマンドを入力しなければならないところだコメントに空行で
Trying <host>...
Connected to static-<host>.nycmny.fios.verizon.net.
Escape character is '^]'.
# empty line for prompt
:
^Ai20101\n
# server prints out data
somedatalinehere
^]
# escape to telnet prompt like below
telnet>
telnet> quit\n
connection closed.
# returns to local terminal prompt
しかし、私はPythonでこれを行うとき:
tn = telnetlib.Telnet(host, 10001)
tn.read_until("\r\n", timeout=1) # nothing matched, returns ''
tn.read_until("", timeout=1) # nothing matched, returns ''
# thus
tn.write("^Ai20101\n")
time.sleep(0.1) # wait 0.1s for next prompt
tn.write("^]")
time.sleep(0.1)
tn.write("quit\n")
tn.read_all() # This hangs as if connection wasn't closed.
ありがとうございますが、私はまだ空の文字列がまったく同じです。しかし、私はあなたの説明を本当に理解していません。あなたは精緻化できますか? '$'は私のクライアントからのプロンプトですが、なぜ 'read_until(" $ ")'で読むべきですか? – PieOhPah
@PieOhPah、単なる 'telnet'(Pythonはまだありません)を使ってサーバに接続すると、server_からこのプロンプトが返されます。私の例ではドル記号の代わりにそれをコピーして貼り付けます。 – ForceBru
私が投稿したサーバーからの返答に対して、あなたが言うことを明確にするために答えを編集できますか?それはまさにサーバが返答するものであり、どこにでも '$'のようなプロンプトはありません。 – PieOhPah