How to fix ConnectTimeout error in Python requests?

ConnectTimeout occurs when the website you are trying to connect to doesn't respond to your connect request in time. You can simulate this error for a website by using a custom connect timeout in your request.get() call:

import requests

# Timeout is in seconds
connect_timeout = 0.1
read_timeout = 10
response = requests.get("https://scrapingbee.com/", timeout=(connect_timeout, read_timeout))

If you are sure your IP is not being blocked by the website and the website is working fine, then you can fix this error by increasing the connect timeout value:

import requests

connect_timeout = 6
read_timeout = 10
response = requests.get("https://scrapingbee.com/", timeout=(connect_timeout, read_timeout))

Related Requests web scraping questions: