I'm trying to connect to my corporate's internal webpages through the requests package, but since python does not use the windows default trusted certificates the connection is denied. I found out that wincertstore can be used to fetch the windows default certificates. But I'm still not sure how to use that along with the my request. Below is the code I have tried so far.............
import requests, socket, atexit, ssl, wincertstore
from requests.auth import HTTPBasicAuth
certfile = wincertstore.CertFile()
certfile.addstore("CA")
certfile.addstore("ROOT")
atexit.register(certfile.close)
ssl_sock = ssl.wrap_socket(s,ca_certs=certfile.name,
cert_reqs=ssl.CERT_REQUIRED)
requests.get(url)
I get the following error...................
requests.exceptions.SSLError: HTTPSConnectionPool(host='myhost', port=443): Max retries exceeded with url: myurl (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
I am able to use wget on the same url and download the content.
wget --no check certificate --user=my username --password=my password URL
But I am not interested in downloading the content as I only need to scrape a small portion of the webpage content.
Pythin version = 3.6.5
Wincertstore link - Link
Thanks in advance for your help..............
wget
command that works, and a link to where you found thiswincertstore
code, and which Python version you're using. (Ifwincertstore
is this project, it's just a backport of the code in Python 3.4+ to 2.3-3.3, which hasn't been updated since 3.4 came out, so I doubt it would be much help for a problem in 3.6, but in 2.7 it might.) – Toughenwget
command isn't using your Windows certs, it's ignoring them, and not doing any validation. So (a) do you know your certs are installed correctly in the first place? And (b) have you tried tellingrequests
to ignore validation as well? If so, show us the code, and what happened. And also, tell us whether making that work would be acceptable. – Toughen