Web.datareader doesn't work for me

my code:

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web

style.use('ggplot')

start = dt.datetime(2000,1,1)
end = dt.datetime(2016,12,31)

df = web.DataReader('TSLA','yahoo',start, end)
print(df.tail(6))

My result:

C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Scripts\python.exe C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\main.py 
Traceback (most recent call last):
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
                ^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 1075, in _create
    self.do_handshake()
  File "C:\Users\cshang\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/TSLA/history?period1=946728000&period2=1483271999&interval=1d&frequency=1d&filter=history (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\main.py", line 12, in <module>
    df = web.DataReader('TSLA','yahoo',start, end)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\pandas_datareader\data.py", line 379, in DataReader
    ).read()
      ^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\pandas_datareader\base.py", line 253, in read
    df = self._read_one_data(self.url, params=self._get_params(self.symbols))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\pandas_datareader\yahoo\daily.py", line 149, in _read_one_data
    resp = self._get_response(url, params=params, headers=self.headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\pandas_datareader\base.py", line 155, in _get_response
    response = self.session.get(
               ^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\requests\sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cshang\PycharmProjects\if\read\pythonforfinance\venv\Lib\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/TSLA/history?period1=946728000&period2=1483271999&interval=1d&frequency=1d&filter=history (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)')))

Process finished with exit code 1

How do I mitigate this?

I tried the example here.
and I get similar result.
So this is a bug somewhere and you may like to check on stack exchange or on github.

Its a problem with certificate verification. Does the windows python have access to
an up to date certificate store?

I don’t know, how do I update it?