0

I'm on a corporate network I need to use certificates for to get access to certain pages. I've tried looking around online for a module that'll retrieve an HTTPS webpage and also allow me to specify which certificate I want to use. I have this code:

import requests
page = requests.get("https://k9ballistics.com/",'lxml')
thing = page.content
thing = thing.split('\n')
for m in thing:
    if '<tr>' in m:
        print m

This works on retrieving a normal HTTPS page, but when I try to access our page it throws this error:

requests.exceptions.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

I was hoping to find a way to do it with a module that already comes with Python as opposed to relying on a pip installed package for portability's sake.

I'm on Windows, but I have my certificates from my linux workstation in a folder I'd like to point to, and also have Ubuntu Bash on Windows.

1
  • the URL listed is an example of a normal HTTPS site that I can retrieve source code from. The internal domain is not listed in this question. Commented Apr 27, 2017 at 3:22

1 Answer 1

2

You can pass verify the path to a CA_BUNDLE file or directory with certificates of trusted CAs:

requests.get('https://eg.com', verify='/path/to/certfile.pem')

or persistent:

s = requests.Session()
s.verify = '/path/to/certfile.pem'

Also you can ignore verifying the SSL certificate by verify=False.

Have a look at SSL Cert Verification to see more details.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm still receiving the same error, but in this case I think these may just not be the certificates I need. You answered my question though so thank you for that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.