yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

YFTzMissingError('$%ticker%: possibly delisted; No timezone found') when downloading price data

Open mattpabi opened this issue 1 year ago • 19 comments

Describe bug

Hi, this was an issue I have not seen anybody raise: YFTzMissingError. I have been using yfinance for about 2 years now without ever encountering this issue too.

When using yf.download(ticker), a timezone not found error is raised, and it says that the request timed out. It's weird as the code seems to randomly work (without any intervention) every few minutes.

  • It is also worth noting that for some reason, the code's success rate is drastically improved when run in a Jupyter Notebook cell, rather than a .py script.

Thanks in advance.

Simple code that reproduces your problem

yf.enable_debug_mode()  # show debug log
df = yf.download("AAPL")  # <-- suspect


### OUTPUT:

Failed to get ticker 'AAPL' reason: HTTPSConnectionPool(host='query1.finance.yahoo.com', port=443): Read timed out. (read timeout=30)
[*********************100%%**********************]  1 of 1 completed

1 Failed download:
['AAPL']: YFTzMissingError('$%ticker%: possibly delisted; No timezone found')

Debug log

DEBUG    Entering download()
DEBUG     Disabling multithreading because DEBUG logging enabled
DEBUG     Entering history()
DEBUG      Entering history()
DEBUG       AAPL: Yahoo GET parameters: {'period1': '1925-08-13 20:00:00-04:00', 'period2': '2024-07-20 07:28:56-04:00', 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG       Entering get()
DEBUG        url=https://query2.finance.yahoo.com/v8/finance/chart/AAPL
DEBUG        params={'period1': -1400630400, 'period2': 1721474936, 'interval': '1d', 'includePrePost': False, 'events': 'div,splits,capitalGains'}
DEBUG        Entering _get_cookie_and_crumb()
DEBUG         cookie_mode = 'basic'
DEBUG         Entering _get_cookie_and_crumb_basic()
DEBUG          reusing cookie
DEBUG          reusing crumb
DEBUG         Exiting _get_cookie_and_crumb_basic()
DEBUG        Exiting _get_cookie_and_crumb()
ERROR     
          1 Failed download:
ERROR     ['AAPL']: ReadTimeout(ReadTimeoutError("HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Read timed out. (read timeout=10)"))
DEBUG     ['AAPL']: Traceback (most recent call last):
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 466, in _make_request
              self._validate_conn(conn)
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1095, in _validate_conn
              conn.connect()
            File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 652, in connect
              sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/connection.py", line 805, in _ssl_wrap_socket_and_match_hostname
              ssl_sock = ssl_wrap_socket(
                         ^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 465, in ssl_wrap_socket
              ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/util/ssl_.py", line 509, in _ssl_wrap_socket_impl
              return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/ssl.py", line 455, in wrap_socket
              return self.sslsocket_class._create(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/ssl.py", line 1042, in _create
              self.do_handshake()
            File "/usr/local/lib/python3.12/ssl.py", line 1320, in do_handshake
              self._sslobj.do_handshake()
          TimeoutError: _ssl.c:983: The handshake operation timed out
          
          The above exception was the direct cause of the following exception:
          
          Traceback (most recent call last):
            File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 667, in send
              resp = conn.urlopen(
                     ^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 843, in urlopen
              retries = retries.increment(
                        ^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/util/retry.py", line 474, in increment
              raise reraise(type(error), error, _stacktrace)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/util/util.py", line 39, in reraise
              raise value
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 789, in urlopen
              response = self._make_request(
                         ^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 490, in _make_request
              raise new_e
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 468, in _make_request
              self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
            File "/usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py", line 369, in _raise_timeout
              raise ReadTimeoutError(
          urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Read timed out. (read timeout=10)
          
          During handling of the above exception, another exception occurred:
          
          Traceback (most recent call last):
            File "/usr/local/lib/python3.12/site-packages/yfinance/multi.py", line 268, in _download_one
              data = Ticker(ticker).history(
                     ^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/utils.py", line 104, in wrapper
              result = func(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/base.py", line 78, in history
              return self._lazy_load_price_history().history(*args, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/utils.py", line 104, in wrapper
              result = func(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/scrapers/history.py", line 140, in history
              # Date range in past so safe to fetch through cache:
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/utils.py", line 104, in wrapper
              result = func(*args, **kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/yfinance/data.py", line 366, in get
              response = self._session.get(**request_args)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests_cache/session.py", line 127, in get
              return self.request('GET', url, params=params, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests_cache/session.py", line 183, in request
              return super().request(method, url, *args, headers=headers, **kwargs)  # type: ignore
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
              resp = self.send(prep, **send_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests_cache/session.py", line 230, in send
              response = self._send_and_cache(request, actions, cached_response, **kwargs)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests_cache/session.py", line 254, in _send_and_cache
              response = super().send(request, **kwargs)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
              r = adapter.send(request, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "/usr/local/lib/python3.12/site-packages/requests/adapters.py", line 713, in send
              raise ReadTimeout(e, request=request)
          requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='query2.finance.yahoo.com', port=443): Read timed out. (read timeout=10)
          
DEBUG    Exiting download()

Bad data proof

No response

yfinance version

0.2.41

Python version

3.12.4

Operating system

No response

mattpabi avatar Jul 20 '24 11:07 mattpabi

Each command-line Python re-run will fetch a new crumb to initialise the new data singleton. But Jupyter persists Python state so no re-fetch happens? That could explain random difference.

ValueRaider avatar Jul 20 '24 13:07 ValueRaider

Each command-line Python re-run will fetch a new crumb to initialise the new data singleton. But Jupyter persists Python state so no re-fetch happens? That could explain random difference.

Thanks, I see. Any way to solve this issue though? It's quite troublesome to scrape on-demand with this error.

Especially since I can't find anyone who has had this YFtz error with a fix

mattpabi avatar Jul 20 '24 15:07 mattpabi

I have been having the same issue. The data return randomly, I have also been using just the endpoint daily for the last 3 years and same thing there. This has been happening for about one month now. And same as you, when I run my code on Jupiter note book the data is more consistent, but still takes quite a bit longer than it used to. If you play with Yahoo Finance itself (pulling up a ticket and changing timeframes) the data is inconsistent there too.

TheSardOz avatar Jul 21 '24 10:07 TheSardOz

the same to me

quanxiang-liu avatar Jul 21 '24 12:07 quanxiang-liu

same issue

fabiodm7 avatar Jul 22 '24 01:07 fabiodm7

same issue

martinbouhier avatar Jul 23 '24 22:07 martinbouhier

Spamming "same" not helping, use the reaction feature.

https://github.com/ranaroussi/yfinance#developers-want-to-contribute

ValueRaider avatar Jul 24 '24 08:07 ValueRaider

Can we assume this is an issue from Yahoo's API, and not the yfinance package?

mattpabi avatar Jul 24 '24 11:07 mattpabi

Experienced the same problem with version 0.2.41 (with python 3.12.2) , and for the same code somehowever I got a '0.2.28' version in a different environment(with python 3.12.4) working perfectly well....

oxhaowang avatar Aug 15 '24 01:08 oxhaowang

Only 1 request change since 0.2.28: adding cookie & crumb in 0.2.32, 9 months ago. Cookie is cached, but cache might not work in Jupyter so cookie fresh in each notebook.

ValueRaider avatar Aug 15 '24 09:08 ValueRaider

After some heavy testing, it appears Yahoo has blocked some of my requests.

On the failed machine (a Linux server) it got the 403 Forbidden Error, whilst the working machine(a Mac) also using wget method would complain Openssl error instead.

oxhaowang avatar Aug 16 '24 15:08 oxhaowang

same problem

JIeJaitt avatar Oct 23 '24 01:10 JIeJaitt

I had the same issue. Traced the issue back to my ad blocker. After I whitelisted fc.yahoo.com it all worked as expected.

fdriessen avatar Oct 24 '24 21:10 fdriessen

I was using Pi-hole, and this domain was blocked. I requested that the maintainer remove it from the block list, and it worked fine.

fabiodm7 avatar Oct 25 '24 01:10 fabiodm7

I am having the same issue. It occurs more often when pulling a large number of tickers. And sometimes a ticker works and sometimes it doesn't. The ticket is still open, so I guess no solution has been found yet, correct? Btw. I do not have an ad-blocker. I only got Google Chrome, which already includes some form of an ad-blocker. I whiteliste finance.yahoo.com and yahoo.com but the problem still persists.

PeterSchober005 avatar Nov 14 '24 09:11 PeterSchober005

I've left ticket open because ideally YF would detect that fc.yahoo.com is blocked and handle gracefully (nice message), not blow up.

ValueRaider avatar Nov 14 '24 21:11 ValueRaider

@ValueRaider Many thanks for the info!

When typing in "fc.yahoo.com" into the browser, it opens yahoo.com. Is this normal or does this mean I am being re-directed?

I am facing the following problem:

  • I am downloading a large number of tickers (Russell3000 stocks).

  • Platform used: Colab.Resarch.Google.com

  • After 600 or 700 tickers, it fails to download the tickers, giving the following error messages: [************ 26% ] 699 of 2677 completedERROR:yfinance:Failed to get ticker 'AVDL' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 701 of 2677 completedERROR:yfinance:Failed to get ticker 'CMCL' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 702 of 2677 completedERROR:yfinance:Failed to get ticker 'RBA' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 702 of 2677 completedERROR:yfinance:Failed to get ticker 'DAKT' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 704 of 2677 completedERROR:yfinance:Failed to get ticker 'IMXI' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 705 of 2677 completedERROR:yfinance:Failed to get ticker 'SJM' reason: Expecting value: line 1 column 1 (char 0) ERROR:yfinance:Failed to get ticker 'RDN' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 707 of 2677 completedERROR:yfinance:Failed to get ticker 'FSS' reason: Expecting value: line 1 column 1 (char 0) ERROR:yfinance:Failed to get ticker 'AWI' reason: Expecting value: line 1 column 1 (char 0) [************ 26% ] 708 of 2677 completedERROR:yfinance:Failed to get ticker 'AVD' reason: Expecting value: line 1 column 1 (char 0) ERROR:yfinance:Failed to get ticker 'RDNT' reason: Expecting value: line 1 column 1 (char 0) [************* 27% ] 710 of 2677 completedERROR:yfinance:Failed to get ticker 'CRS' reason: Expecting value: line 1 column 1 (char 0) ERROR:yfinance:Failed to get ticker 'AEIS' reason: Expecting value: line 1 column 1 (char 0)

  • However, when downloading each ticker individually, it works! For example, AVDL can be downloaded when it is downloaded alone.

Any support is deeply appreciated! Many thanks in advance!

PeterSchober005 avatar Nov 15 '24 08:11 PeterSchober005

Just a quick note: it seems like yf.download stopped being able to handle a ticket list with more than 600 or 700 tickers. So it does not work anymore that a ticket list with 3000 tickers is downloaded at once. I have to split this large ticket list into multiple ticket list (each one with 500 tickers). This works!

PeterSchober005 avatar Nov 15 '24 09:11 PeterSchober005

This issue manifests itself with even 1 ticker. Example:

import yfinance as yf

ticker = "AAPL"
start_date = "2024-11-01"
end_date = "2024-11-15"
data = yf.download(ticker, start=start_date, end=end_date)
print(data.head())
data.to_csv(f"{ticker}_stock_data.csv")

Output:

Failed to get ticker 'AAPL' reason: HTTPSConnectionPool(host='fc.yahoo.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10e714590>: Failed to establish a new connection: [Errno 61] Connection refused'))
[*********************100%***********************]  1 of 1 completed

1 Failed download:
['AAPL']: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')
Empty DataFrame
Columns: [(Adj Close, AAPL), (Close, AAPL), (High, AAPL), (Low, AAPL), (Open, AAPL), (Volume, AAPL)]
Index: []

And this was my first try in 24 hours, so it's not that I'm exceeding any limit here.

RamXX avatar Nov 16 '24 22:11 RamXX

maybe can it solve with this?: https://ranaroussi.github.io/yfinance/advanced/caching.html I have the same issue

GabrielTehozol avatar Dec 23 '24 19:12 GabrielTehozol

@PeterSchober005 hi, can you solve the issue?, Many thanks in advance!

GabrielTehozol avatar Dec 24 '24 16:12 GabrielTehozol

I have the same issue on one of my laptops. I have release 0.2.51, in Python 3.12.8. For a lot of tickers, I got the same error message: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')

Interestingly, in my another laptop, also with yfinance 0.2.51 as well, but in Python 3.11.9, it is working correctly. Well, the two environments are not identical.... but it would be weird to say the differences in the environment cause this difference.

stephenhky avatar Dec 27 '24 22:12 stephenhky

I have the same issue on one of my laptops. I have release 0.2.51, in Python 3.12.8. For a lot of tickers, I got the same error message: YFTzMissingError('$%ticker%: possibly delisted; no timezone found')

Interestingly, in my another laptop, also with yfinance 0.2.51 as well, but in Python 3.11.9, it is working correctly. Well, the two environments are not identical.... but it would be weird to say the differences in the environment cause this difference.

For your information, I just installed another environment of Python 3.11.11, and the error disappeared. It is weird to me that the problem is fixed in this way. But FYI.

stephenhky avatar Dec 28 '24 04:12 stephenhky

I have to add a comment that this problem appears and dissappears from time to time.... so I do not know what causes it. It might be something beyond yfinance.

stephenhky avatar Dec 28 '24 23:12 stephenhky

Hi, perhaps a bit late to this discussion but in case anyone else is having this problem, a couple things I did to solve:

First, a test script:

import yfinance as yf
import time
import pandas as pd

def test_yahoo_finance():
    try:
        # Add a small delay before the request
        time.sleep(1)
        
        # Create a Ticker object
        ticker = yf.Ticker('AAPL')
        
        # Get historical data
        hist = ticker.history(
            start='2023-01-01',
            end='2024-03-01',
            interval='1d'
        )
        
        if hist.empty:
            print("Error: No data received")
            return False
            
        print(f"Successfully retrieved {len(hist)} data points")
        print("\nFirst few rows of data:")
        print(hist.head())
        return True
        
    except Exception as e:
        print(f"Error retrieving data: {str(e)}")
        return False

if __name__ == "__main__":
    test_yahoo_finance()

I think the issue was rate limiting. I was getting an "429 Too Many Requests" error from Yahoo Finance. Adding that sleep() made it start working. Just to be safe, I also updated to the current latest yf package, 0.2.54 at this moment.

jimn avatar Mar 12 '25 18:03 jimn

Hi, perhaps a bit late to this discussion but in case anyone else is having this problem, a couple things I did to solve:

First, a test script:

import yfinance as yf
import time
import pandas as pd

def test_yahoo_finance():
    try:
        # Add a small delay before the request
        time.sleep(1)
        
        # Create a Ticker object
        ticker = yf.Ticker('AAPL')
        
        # Get historical data
        hist = ticker.history(
            start='2023-01-01',
            end='2024-03-01',
            interval='1d'
        )
        
        if hist.empty:
            print("Error: No data received")
            return False
            
        print(f"Successfully retrieved {len(hist)} data points")
        print("\nFirst few rows of data:")
        print(hist.head())
        return True
        
    except Exception as e:
        print(f"Error retrieving data: {str(e)}")
        return False

if __name__ == "__main__":
    test_yahoo_finance()

I think the issue was rate limiting. I was getting an "429 Too Many Requests" error from Yahoo Finance. Adding that sleep() made it start working. Just to be safe, I also updated to the current latest yf package, 0.2.54 at this moment.

0.2.50 update to 0.2.54,it worked

LXWorkSpace avatar Mar 18 '25 08:03 LXWorkSpace

✅ SOLVED.

!pip install yfinance==0.2.54

nikitakapitan avatar Apr 15 '25 08:04 nikitakapitan

FWIW my VPN was also causing the same symptom.

flammavitae avatar Apr 28 '25 21:04 flammavitae