2

I wrote a python script with requests to send requests a list of domains, I use

try 
  requests.get('http://example.com')
except requests.exceptions.RequestException as e:
  pass

to handle exceptions such as timeout, or too many redirections, as described in Correct way to try/except using Python requests module?.

However, there is an issues that some sites support only http scheme, while others support only https. In other words, if I send request to http://example.com, it does not redirect to https://example.com. Because of this, requests gives "failed to establish a new connection" error, complain that http://example.cm does not exist and terminates the program.

I wonder if there is a way to let me bypass such error, and continue to send request to the next host.

SamTest
  • 299
  • 3
  • 13
  • By continue to next host, do you mean the next domain in the list or the https site of the same failed domain? – Praveenkumar Jun 26 '19 at 04:34
  • The best option is to send a subsequent HTTPS request to the failed site, but it is also acceptable to skip the domain and send HTTP request to the next domain on the list. Basically, i wonder how can such error be caught the same as other exceptions. – SamTest Jun 26 '19 at 13:43

0 Answers0