リクエストを行う関数を非同期で実行したいのですが、エラーが出てしまいます
どうしたらよいでしょうか
よろしくお願いします。
試したこと
import requests import asyncio async def test() : # POST送信 requests.post('localhost:8000') asyncio.ensure_future(test())
エラー出力
Traceback (most recent call last): File /views.py", line 451, in test asyncio.ensure_future(test()) File "/root/.pyenv/versions/3.7.1/lib/python3.7/asyncio/tasks.py", line 580, in ensure_future loop = events.get_event_loop() File "/root/.pyenv/versions/3.7.1/lib/python3.7/asyncio/events.py", line 644, in get_event_loop % threading.current_thread().name) RuntimeError: There is no current event loop in thread 'Thread-1'. /views.py:492: RuntimeWarning: coroutine 'test' was never awaited
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。