<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed for python2 but not in python3

312 Views Asked by At

I have a server (RHEL 7.5) with both python2 (2.7.5) and python3 (3.7.9)

When I run the below code it's passed successfully for python3 but failed for python2

try:   
    import urllib2 #python2
except:
    import urllib.request as urllib2 #python3

req = urllib2.Request('https://pkg.jenkins.io/redhat-stable/jenkins.repo', headers={'User-Agent':'Mozilla/5.0'})
urllib2.urlopen(req)

for python3 I get the output

<http.client.HTTPResponse object at 0x7f1688405850>

But for python2 the below error:

urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)>

I don't want to disable the ssl verification.

What can be issue that python3 is working and failed on python2?

0

There are 0 best solutions below