I have code that suddenly started raising errors while running it. Some time ago worked fine and still works on the PC i was using ~6 months ago (for the same code).
Tracked the problem to yfinance package that raises the error with just:
import yfinance as yf
#Test code w. Apple as ticker
tickerData = yf.Ticker('AAPL')
tickerData.info
The error I am getting is:::
Traceback (most recent call last):
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 364, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connection.py", line 501, in _connect_tls_proxy
socket = ssl_wrap_socket(
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\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\Arttu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1070, in _create
self.do_handshake()
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1341, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\urllib3\util\retry.py", line 574, 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/AAPL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Arttu/Sync/Working On/yfinance_test.py", line 4, in <module>
tickerData.info
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\yfinance\ticker.py", line 143, in info
return self.get_info()
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\yfinance\base.py", line 525, in get_info
self._get_fundamentals(proxy=proxy)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\yfinance\base.py", line 321, in _get_fundamentals
data = utils.get_json(ticker_url, proxy, self.session)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\yfinance\utils.py", line 56, in get_json
html = session.get(url=url, proxies=proxy, headers=user_agent_headers).text
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Arttu\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/AAPL (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)')))
Any idea how to fix (and any idea why the sudden change?) Thanks A
For me it is working, I think it might be the issue with the version . Please install the latest version by
Then your code will work
Output: