How to fix Python requests ReadTimeout error?

ReadTimeout error is seen when using Python requests module for web scraping with explicit timeout parameter:

import requests
response = requests.get("https://httpbin.dev/delay/2", timeout=1.5)  # 1.5 seconds
# will raise
# ReadTimeout: HTTPConnectionPool(host='httpbin.dev', port=80): Read timed out. (read timeout=2)

The ReadTimeout exception means that the request could not be completed in the given time frame. By default, the requests module has no timeout which can hang the whole program indefinitely so this value should always be set to 1-120 seconds depending on the target.

If you're encountering a lot of ReadTimeout exceptions your scraper might be being blocked by the website. For more on that see our guide how to scrape without getting blocked

See related errors: ConnectTimeout

Provided by Scrapfly

This knowledgebase is provided by Scrapfly data APIs, check us out! 👇