Python Forum
Is it possible to add a delay right after a request.get()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to add a delay right after a request.get()
#7
Yes, it is possible to add a delay right after making a request using the requests.get() function in Python. Adding a delay can be useful in situations where you want to control the rate at which you make requests to a web server, especially if you're scraping data or interacting with a web API that has rate-limiting policies.

You can introduce a delay using the time.sleep() function from the time module. Here's an example of how to add a delay of, let's say, 2 seconds after making a GET request:


import requests
import time

url = "https://example.com"
response = requests.get(url)

# Add a 2-second delay
time.sleep(2)

# Continue with your code after the delay
In this example, the time.sleep(2) line will pause the execution of your script for 2 seconds before moving on to the next line of code. You can adjust the delay duration by changing the argument to time.sleep() to suit your needs.

Keep in mind that while adding a delay can help you avoid overloading a server or violating rate limits, it will also make your script run slower. Balancing the delay duration is important to achieve the desired rate of request while ensuring your script remains efficient.
buran write Sep-07-2023, 10:13 AM:
please, don't use triple backquotes to mark code, use python tags instead
Reply


Messages In This Thread
RE: Is it possible to add a delay right after a request.get() - by shoesinquiry - Sep-07-2023, 09:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Request Delay pheadrus 1 3,896 Nov-25-2021, 08:51 PM
Last Post: snippsat
  how can I correct the Bad Request error on my curl request tomtom 8 5,132 Oct-03-2021, 06:32 AM
Last Post: tomtom
  adding a delay on end Daz2264 6 2,531 Sep-29-2021, 02:57 PM
Last Post: deanhystad
  python delay without interrupt the whole code Nick_tkinter 4 5,229 Feb-22-2021, 10:51 PM
Last Post: nilamo
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 4,793 Nov-20-2020, 02:26 PM
Last Post: greenpine
  configure delay on only one link using python3 HiImAl 3 2,756 Oct-21-2020, 07:51 PM
Last Post: buran
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,970 Jun-18-2020, 08:07 AM
Last Post: buran
  Keyboard commands and delay/latency RungJa 0 2,162 Mar-29-2020, 01:28 PM
Last Post: RungJa
  Unwanted delay between looped synth plays WolfeCreek 1 2,347 Aug-02-2018, 09:24 PM
Last Post: Vysero
  Vpython Delay in plotting points SohaibAJ 0 2,084 Jul-30-2018, 08:44 PM
Last Post: SohaibAJ

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020