title: Getting error: "certificate verify failed: unable to get local issuer certificate" trying to webscrape pdfs in PyCharm
body: <p>Here is the code that I have been trying to fix:</p>
  <pre><code>import requests
  from urllib.parse import urljoin
  from bs4 import BeautifulSoup
  url = &quot;https://www.pbs.gov.pk/node/3391/?name=001&quot;
  
  #If there is no such folder, the script will create one automatically
  folder_location = r'infoFA'
  if not os.path.exists(folder_location):os.mkdir(folder_location)
  response = requests.get(url)
  soup= BeautifulSoup(response.text, &quot;html.parser&quot;)     
  for link in soup.select(&quot;a[href$='.pdf']&quot;):
      #Name the pdf files using the last portion of each link which are unique in this case
      filename = os.path.join(folder_location,link['href'].split('/')[-1])
      with open(filename, 'wb') as f:
          f.write(requests.get(urljoin(url,link['href'])).content)
  </code></pre>
  <p>From this, I get the following error in PyCharm:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/connectionpool.py&quot;, line 699, in urlopen
      httplib_response = self._make_request(
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/connectionpool.py&quot;, line 382, in _make_request
      self._validate_conn(conn)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/connectionpool.py&quot;, line 1010, in _validate_conn
      conn.connect()
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/connection.py&quot;, line 411, in connect
      self.sock = ssl_wrap_socket(
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/util/ssl_.py&quot;, line 449, in ssl_wrap_socket
      ssl_sock = _ssl_wrap_socket_impl(
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/util/ssl_.py&quot;, line 493, in _ssl_wrap_socket_impl
      return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py&quot;, line 500, in wrap_socket
      return self.sslsocket_class._create(
    File &quot;/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py&quot;, line 1040, in _create
      self.do_handshake()
    File &quot;/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py&quot;, line 1309, in do_handshake
      self._sslobj.do_handshake()
  ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/adapters.py&quot;, line 439, in send
      resp = conn.urlopen(
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/connectionpool.py&quot;, line 755, in urlopen
      retries = retries.increment(
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/urllib3/util/retry.py&quot;, line 574, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.pbs.gov.pk', port=443): Max retries exceeded with url: /node/3391/?name=001 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/main.py&quot;, line 10, in &lt;module&gt;
      response = requests.get(url)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/api.py&quot;, line 75, in get
      return request('get', url, params=params, **kwargs)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/api.py&quot;, line 61, in request
      return session.request(method=method, url=url, **kwargs)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/sessions.py&quot;, line 542, in request
      resp = self.send(prep, **send_kwargs)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/sessions.py&quot;, line 655, in send
      r = adapter.send(request, **kwargs)
    File &quot;/Users/justinlesko/PycharmProjects/pythonProject8/venv/lib/python3.9/site-packages/requests/adapters.py&quot;, line 514, in send
      raise SSLError(e, request=request)
  requests.exceptions.SSLError: HTTPSConnectionPool(host='www.pbs.gov.pk', port=443): Max retries exceeded with url: /node/3391/?name=001 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)')))
  
  Process finished with exit code 1
  </code></pre>
  <p>I have tried the following to fix this ssl error:
  -setting verify to &quot;False&quot; in <code>requests.get(url)</code>
  -installing and reinstalling certificates from the python 3.9 folder I have
  -setting unknown certificates to &quot;trust&quot; in preferences</p>