How to Rate Limit Async Requests in Python
Quick tutorial on how to limit asynchronous python connections when web scraping. This can reduce and balance out web scraping speed to avoid scraping pages too fast and blocking.
Response status code 520 generally means the server failed to generate a valid response (Often related to Cloudflare). This could be caused by technical issues however in web scraping this can also mean insufficient request details or web scraper blocking.
To avoid status code 520 when web scraping ensure that sent requests contain all required headers like secret/CSRF tokens, Origin, Referer and other commonly required details. If it's a POST request make sure the sent body matches expected format.
Otherwise, it's possible the scraper is being identified and blocked. For that refer to our how to scrape without being blocked guide which covers all of the ways to prevent web scrapers from being identified.