Reputation: 61
I have a program and in order verify that the user doesnt download such big files using input i need a time limit on how long each request is allowed to take.
Does anyone know a good way to put a time limit(/lifetime) on each python requests get requests so if it takes 10 seconds an exception will be thrown.
Thanks
Upvotes: 1
Views: 2555
Reputation: 1732
You can pass an additional timeout parameter to every request you make. This is always recommended as it will make your code more robust to hanging indefinitely in case you don't receive a response from the other end.
requests.get('https://github.com/', timeout=0.001)
Read the official python request documentation for timeouts here.
Upvotes: 1
Reputation:
You can define your own timeout like:
requests.get('https://github.com/', timeout=0.001)
Upvotes: 0