前提
pythonのresponderを使用して、webアプリを作成しています。
websocket送信を行うためのトリガーとして、同一pyファイル内の関数からのpost送信を考えています。
実現したいこと
・同一pyファイル内のpost_test関数から、@api.route('/ws1', websocket=True)へ
postを送信したい。
発生している問題・エラーメッセージ
INFO: 127.0.0.1:62215 - "POST /ws1 HTTP/1.1" 404 Not Found
該当のソースコード
python
1import requests 2import responder 3import datetime 4import time 5import multiprocessing 6 7 8def post_test(): 9 while True: 10 POST_URL = "http://127.0.0.2:8080/ws1" 11 request_body = {"9999":"on"} 12 response = requests.post(POST_URL, json=request_body) 13 time.sleep(2) 14 15 16api = responder.API() 17@api.route('/') 18class Home: 19 def on_get(self, req, resp): 20 """ 21 22 """ 23 24 param = None 25 26 resp.html = api.template('home.html', param=param) 27 28@api.route('/io_check') 29class ioCheck: 30 def on_get(self, req, resp): 31 """ 32 33 """ 34 35 resp.content = api.template('io_check_post_snmpget.html') 36 37 async def on_post(self, req, resp): 38 """ 39 """ 40 41 api.redirect(resp, '/io_check') 42 43 44@api.route('/ws1', websocket=True) 45async def websocket1(ws1): 46 await ws1.accept() 47 await ws1.accept() 48 data = await req.media() 49 7777 = data.get('9999') 50 print(data) 51 print(7777) 52 53 54if __name__ == '__main__': 55 p1 = multiprocessing.Process(target=post_test) 56 p1.start() 57 58 api.run(port=8080, address="127.0.0.2", debug=True)
あなたの回答
tips
プレビュー