Skip to content
Advertisement

How to resolve RuntimeError: await wasn’t used with future using aiohttp and asyncio in python?

I made some pretty simple script which pulls data from clicky.com api but for some reason it does not work as expected from time to time.

Sometimes it gets results but another time I am getting the following errors which I cant debug. I am fairly new to asyncio and aiohttp

JavaScript

How to debug this? Whats the problem here?

edited: Here is my code for you to test:

JavaScript

Advertisement

Answer

I actually found a solution by myself.

  1. Instead of aiohttp I used httpx
  2. I used timeout with every request
  3. I removed unnecessary await

Changes in an original code below. Now the script run 100% stable. To be frank I am not sure which of these changes had the biggest impact but it works as expected.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement