Set time limit for the download response of request.get() [Django and Python]

Asked

Viewed 144 times

0

I am having problems with the server data return time when I make a get request. The server starts the data transmission, but sometimes it takes too long to complete the upload (more than 30 seconds).

I need to limit download waiting time. If the download time exceeds x seconds, then cancel the operation. I’ve already tried two ways:

Use the request timeout attribute

import request

r = request.get('https://www.umaURL.com', timeout=5) 

But it doesn’t work, because this timeout only limits the server’s response time. It doesn’t limit download time.

I also tried using the eventlet. Timeout(), but it generates an error when I run the Django server .

import eventlet
eventlet.monkey_patch()

try:
    with eventlet.Timeout(4):

        r = requests.get('https://www.umaURL.com')

except:
    pass

However, when I start the Django server (python Manage.py runserver) I get the following error:

AttributeError: module 'select' has no attribute 'poll'

Does anyone know any solution?

  • Have you seen the documentation of timeouts of requests? You can pass a tuple with two values where the second is the timeout of read. Maybe that’s what you’re looking for.

  • I also tried to pass a tuple on the request timeout, but it didn’t work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.