Python requests ReadTimeout error: how to fix it?

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

import requests
response = requests.get("http://httpbin.org/delay/2", timeout=1.5)  # 1.5 seconds
# will raise
# ReadTimeout: HTTPConnectionPool(host='httpbin.org', 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