title: Python certificate verify failed: unable to get local issuer certificate
body: <p>I am a novice programmer so pardon my mistakes. I have written the below code to verify a list of Websites are still active and all my work is based off this problem statement.</p>
  <p>The script is able to check most sites but stumbled with below error for <a href="https://precisionit.net/" rel="nofollow noreferrer">https://precisionit.net/</a></p>
  <pre><code>&lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)&gt;
  </code></pre>
  <p>The above URL opens fine in Firefox and Chrome but fails to open in Python code. I have updated certifi and used it in my code as suggested by many folks but the error would not go away.</p>
  <p>I am using Conda Python Env and I also executed the below command</p>
  <pre><code>conda install -c conda-forge certifi
  </code></pre>
  <p>There were multiple posts that suggested running &quot;Install Certificates.command&quot; which does not apply to Conda Python so I downloaded Python 3.9 installer and executed &quot;Install Certificates.command&quot; and executed the script with Python 3.9 yet no luck. I feel the issue is that even with latest version of certifi the sites certificate is not validated. Although <a href="https://pypi.org/project/certifi/" rel="nofollow noreferrer">certifi page</a> says the list is based off Mozilla’s root certificates I guess it's not an exact replica which is why Firefox is able to open the site. Not sure if my understanding makes sense and will be glad to be corrected.</p>
  <p>Pasting my script below. I am not sure what else needs to be done to fix the issue, kindly advise.</p>
  <pre><code>import urllib.request
  import sys
  import certifi
  import ssl
  
  def checkURL(url):
      try: 
          
          hdr = { 'User-Agent' : 'Mozilla/79.0 (Windows NT 6.1; Win64; x64)' }
          req=urllib.request.Request(url,headers=hdr)
          r = urllib.request.urlopen(req,timeout=100,context=ssl.create_default_context(cafile=certifi.where()))
          
      except Exception as e:
          #print(r.read())
          print('Failed Connecting to Website')
          print(e)
          return(1)
  
      print(r.status)
      finalurl = r.geturl()
      if r.status==200:
          print(finalurl)
          return(0)
      else:
          print(&quot;Website Not Found&quot;)
          return(2)
  
  checkURL('https://precisionit.net/')
  </code></pre>