I am trying to scrape a website, but am receiving the following error:
('Connection aborted.', OSError("(60, 'ETIMEDOUT')",))
I tried to change the timeout = None within response.get(), but I still received the error.
How should I handle the above error given the below code? For some reason, this error only appears when I try and scrape that url, all others have worked fine for me.
The below code was suggested based off of this question.
# Import packages
import requests
from bs4 import BeautifulSoup
#Input URL
url = "https://www...."
# Try requests.get()
try:
r = requests.get(url)
except requests.ConnectionError as e:
print("OOPS!! Connection Error. Make sure you are connected to Internet. Technical Details given below.\n")
print(str(e))
except requests.Timeout as e:
print("OOPS!! Timeout Error")
print(str(e))
except requests.RequestException as e:
print("OOPS!! General Error")
print(str(e))
except KeyboardInterrupt:
print("Someone closed the program")
I also tried a retry mechanism, but to no luck, as suggested here:
for i in range(0,10):
while True:
try:
r = requests.get(url)
except requests.ConnectionError as e:
print("OOPS!! Connection Error. Make sure you are connected to Internet. Technical Details given below.\n")
print(str(e))
continue
break