Home > other >  How can I fix SSL error, nothing seems to work?
How can I fix SSL error, nothing seems to work?

Time:03-04

I was just about to do some testing with the Nasa API to see if it works, but I'm getting SSL errors every time I run the code. I tried providing SSL context, and setting verify=False, but nothing seems to work.

Here's the request:

with urllib.request.urlopen(url=apod["hdurl"], context=ctx) as u, \
    open(filename, 'wb') as f:
        f.write(u.read())

Above the request, I have defined the context:

ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE

Since I'm on MacOS I've also tried going Applications > Python 3.8 > Install certificates command, but it doesn't seem to work. I'm thinking something might be wrong with my Python interpreter.

Also, here's the exception I get:

requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1124)

Seems like the library it's self is having trouble sending requests, if i go:

nasa = nasapy.Nasa(key=key)
nasa.picture_of_the_day()

I get the same SSL certificate error. How might I go about solving this?

Help much appreciated!

CodePudding user response:

I fixed it, i had to go into the library files venv/bin/api.py and inside the libraries code where the request is, set verify=False.

Works now.

  • Related