Next code works fine if I use time.sleep(0.1)
instead of await asyncio.sleep(0.1)
On await asyncio.sleep(0.1)
I am getting error:
[ERROR] Exception occurred while handling uri: 'http://127.0.0.1:8000/api/new-answer'
My Code:
@app.route("/api/new-answer", methods=["POST"])
async def new_answer(request):
r=requests.post(url, json=json_obj, headers={"Accept":"application/json", "Authorization": "bearer " + my_token}) # формат ответа: {'id': 53, 'status': 'new'}
answer = r.json()
if r.status_code == 200:
while(True):
await asyncio.sleep(0.1)
# time.sleep(0.1)
url = "https://site.com/v2/complex/status?id=" + str(latest_status_id)
r=requests.get(url, headers={"Accept":"application/json", "Authorization": "bearer " + my_token})
data = r.json()
if data['status'] == 'completed':
pass # some logic here
P.S. the answer from server may take up to 2 minutes.