I was trying to write a simple script to check if a website has a ssl certificate or not. I came across some tutorials that suggested to use the requests.get() function with the verify parameter set as to be True but whenever I try to target any website that does not have a SSL certificate the program is not showing any error. The link I am trying to test it on is : http://dtdev.atwebpages.com/ and the code is
import requests
response = requests.get("http://dtdev.atwebpages.com/", verify = True)
print(response.text)
CodePudding user response:
verify
is for checking whether an https
certificate is valid or not. So your use-case (i.e. visiting an http
endpoint) doesn't apply here as there are no certificates to validate.
If you want to check whether or not a website supports https
you could just try to access its https endpoint and see whether or not you get an error. For example:
from requests.exceptions import ConnectionError
try:
response = requests.head("https://dtdev.atwebpages.com/")
except ConnectionError:
print("Figure out why we couldn't connect")
In addition:
You also just try to access the http
endpoint and see whether or not your connection got upgraded. Like here.