How to fix python requests ConnectTimeout error?

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

import requests
connect_timeout = 0.1
read_timeout = 10
response = requests.get("http://scrapfly.io/", timeout=(connect_timeout, read_timeout))
# will raise
# ConnectTimeout: HTTPConnectionPool(host='scrapfly.io', port=80):

The ConnectTimeout exception means that the server has refused to connect with our client in the given amount of time. This could be because of technical difficulties or explicit bot blocking. Try increasing the connect timeout.

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

See related errors: ReadTimeout

Provided by Scrapfly

This knowledgebase is provided by Scrapfly — a web scraping API that allows you to scrape any website without getting blocked and implements a dozens of other web scraping conveniences. Check us out 👇