flip
flip

Reputation: 61

Put a time limit on a request

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

Answers (2)

Abhishek Jaisingh
Abhishek Jaisingh

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

user13103373
user13103373

Reputation:

You can define your own timeout like:

requests.get('https://github.com/', timeout=0.001)

Upvotes: 0

Related Questions