0

I'm trying to get a resource from a url inside a route on a web server without blocking it since getting it sometimes takes 11 seconds+. I switched from flask to aiohttp for this.

async def process(request):
    data = await request.json()
    req = urllib.request.Request(
            request["resource_url"], 
            data=None, 
            headers=hdrs
        )
    # Do processing on the resource 

But I'm not sure how to make the call and would it allow other calls to be made to this route while the resource is getting fetched?

K41F4r
  • 1,443
  • 1
  • 16
  • 36
  • You should use aiohttp to make the request. Although if you want to respond to the client before the request completes, you may want to use a background worker (e.g., celery, rq). – dirn Apr 16 '19 at 16:08
  • as @dirn suggested you should use aiohttp please refer this link to make use of aiohttp client https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request – rsb Apr 23 '19 at 04:11

0 Answers0