Kuni
Kuni

Reputation: 865

Python SSL Certificate Error using request

I'm getting the following error while using request package in Python.

'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

I'm trying to access a link using the following code:

content = requests.get(link, verify=True, headers={"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 12871.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"})
    

I searched for some solutions and found a few that talked about Install Certificate.command, but I can't find the file in my Python directory. I'm using Python 3.8. Any suggestion on how to get this resolved?

Upvotes: 2

Views: 2250

Answers (1)

Kuni
Kuni

Reputation: 865

I had to provide the certificate to prevent this error from occuring.

cert = requests.certs.where()
        page = requests.get(link, 
                            verify=cert, 
                            headers={"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 12871.102.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.141 Safari/537.36"})

This worked for me

Upvotes: 2

Related Questions