Pythonのtelnetlibを使用してArgosデータのダウンロードを自動化しようとしていますが、すべての出力をダウンロードする方法がわからないようです。私の問題の一部は、コマンドの一見非同期の性質を本当に理解していないことかもしれません。
コードは次のとおりです。
tn = telnetlib.Telnet(host = HOST, timeout = 60)
with open("argos_prv_{0}-1.txt".format(now_str), 'w') as of:
tn.read_until("Username: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(password + "\n")
tn.read_until("/")
# Here's the command I'm trying to get the results of:
tn.write("prv,,ds,{0:d},009919,009920\n".format(start_doy))
# At this point, it's presumably dumped it all
tn.read_until("ARGOS READY")
tn.read_until("/")
# Logging out
tn.write("lo\n")
lines = tn.read_all()
of.write(lines)
of.flush()
コードは問題なく実行されているように見えますが、出力ファイルを見ると、すべてが含まれているわけではなく、ランダムなポイントで切り取られています。実際のtelnetセッションで同じコマンドを入力すると、問題なく機能します。
read_all()
ログアウトした後の試行と関係があるように感じますtn.write("lo\n")
が()、telnetlibのサンプルドキュメントを見ると、ほぼ次のようになっています。
とにかく、私の質問は:誰かが私がここで間違っていることを見ることができますか?prv,,ds
コマンドの結果を取得したいのですが、この特定のコードを使用して取得しているのはその一部だけです。
ありがとう。