Making external http calls using requests package within Daphne

I have a Django project that runs by Daphne, one of my views needs to submit a http request externally using the requests package, unfortunately that package is not async compatible, so if the http call is blocked, the whole Daphne app hangs.

An simplified demo as below:

def view(request):
    # this call will get timed out
    data = requests.get('https://blocked') 
    ...
    return Response(...)

I did some quick search and couldn't find any quick answers. One possibility is to serve these views via Uwsgi, apart from this approach, are there any other quick wins?

Use aiohttp? Problem is that http call is done inside an external package, that I means I will have to modify that external package to use aiohttp

Back to Top