前提・実現したいこと
Python3.7.1でwebsocketよりAPIを取得してるのですが、
2つあるうちの1つのwebsocketだけが稼働中に頻繁に以下の状態で停止しています。
もう1つは今日の正午から現在も問題なく稼働しています。
また両者のコード自体もAPIの問い合わせ先URLが違うだけで、他のコード内容はすべて同じです。
エラーが起きているのは高頻度にメッセージを受信しているwebsocketで
on_message(): が正常に終了しているにも関わらず on_error():が呼ばれているように見受けられます。
しかし簡易的なエラー内容しか表示されず詳細がわからず行き詰った状況です。
解決方針としてはエラー内容がクライアント側で修正できるものであるならばそうしたいと考えています。
よろしくお願いします。
発生している問題・エラーメッセージ
エラーメッセージ
called on_message
~~~~ 中略 ~~~~~
開始時刻: 2019/04/20 20:28:29
called on_error
Connection is already closed.
called on_close
disconnected streaming server
called on_run
Web Socket process ended.
終了時刻: 2019/04/20 20:32:30
該当のソースコード
python
1 # when we get message 2 def on_message(self, ws, message): 3 print("called_on_message") 4 l_posi = 0 5 s_posi = 0 6 7 ~~~~~中略~~~~~ 8 9 print("開始時刻:",time) 10 l_posi = 0 11 s_posi = 0 12 13 # when error occurs 14 def on_error(self, ws, error): 15 print("called on_error") 16 logger.error(error) 17 18 # when websocket closed. 19 def on_close(self, ws): 20 print("called on_close") 21 logger.info('disconnected streaming server') 22 23 # when websocket opened. 24 def on_open(self, ws): 25 print("called on_open") 26 logger.info('connected streaming server') 27 output_json = json.dumps( 28 {'method' : 'subscribe', 29 'params' : {'channel' : self.channel} 30 } 31 ) 32 ws.send(output_json) 33
試したこと
エラー内容の箇所を突き止めようとprint分を挟んでみたが、
特にエラー個所が見当たらずプログラム的なミスは今のところ突き止められていない。
補足情報
try - exception の構文で解決できる場合、書き方を教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/24 11:34
2019/04/24 13:19
2019/04/24 16:15 編集
2019/04/25 05:01
2019/05/12 04:03