Open BeachGuy007 opened 3 months ago
Mysteriously working now
Reappeared again today. Was problematic before open yesterday (9:30am EDT), then mysteriously resolved and worked the rest of the day. Today worked before 9:30am but then after 9:30am get error.
Happened again this morning. All quotes N/A
Working now. I guess intermittent issue? Could be Yahoo servers?
Happening again (5am). Issue with Yahoo servers? Throttling?
Are you spamming? https://github.com/ranaroussi/yfinance/discussions/1513
Ah no. Real issue. Worked fine all day yesterday. Worked this morning for a while then N/A now.
Now some quotes coming through. I think it's yahoo servers(?).
yfinance stores cookie here: https://github.com/ranaroussi/yfinance#persistent-cache-store - does deleting it help?
I am on WIN11 and there is no directory called py-yfinance here: Windows = C:/Users/<USER>/AppData/Local/py-yfinance
I also don't have yf.set_tz_cache_location("custom/cache/location")
All quotes were N/A a second ago and just now flashed real quote.
I also don't have yf.set_tz_cache_location
... how did you check yfinance version?
PS C:\Users\Bill\Documents\Python> pip show yfinance Name: yfinance Version: 0.2.41 Summary: Download market data from Yahoo! Finance API Home-page: https://github.com/ranaroussi/yfinance Author: Ran Aroussi Author-email: ran@aroussi.com License: Apache Location: C:\Users\Bill\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages Requires: beautifulsoup4, frozendict, html5lib, lxml, multitasking, numpy, pandas, peewee, platformdirs, pytz, requests Required-by: PS C:\Users\Bill\Documents\Python>
PIP can be wrong. Use the method in the new issue form.
Back to N/As again
import yfinance as yf ; print(yf.version) 0.2.41
Regardless, if you don't have yf.set_tz_cache_location
then your version must be almost 1-year old or corrupt. https://github.com/ranaroussi/yfinance/commit/59af19d84c73e026730ac2c48310316011fe7efd
Ok I uninstalled yfinance rebooted and reinstalled yfinance. Quotes seem to be working now. Do you think that should clear the issue? I'll let you know if something happens. Thanks for all your help!
pip uninstall yfinance reboot pip install yfinance
New error even after uninstalling/reinstalling.
1 Failed download: 2024-08-21 08:17:14,639:ERROR:['UPRO']: YFPricesMissingError('$%ticker%: possibly delisted; No price data found (period=1d)')
Happens to any/all tickers
Maybe it's their severs? Right at 9:30am all quotes worked today.
1/2 an hour into the trading day and all quotes working fine. Must be something sporadic with Yahoo servers during ETH.
I wrote some reconnection python code and it seems to be working with that.
def handle_connection_error(self):
if not self.connection_active:
if self.reconnect_attempts < self.max_reconnect_attempts:
self.reconnect_attempts += 1
print(f"Connection lost. Attempting to reconnect (Attempt {self.reconnect_attempts}/{self.max_reconnect_attempts})...")
self.display_reconnecting()
self.root.after(self.reconnect_delay, self.update_data) # Wait before retrying
else:
print("Max reconnection attempts reached. Please check your internet connection.")
self.display_connection_error()
else:
self.reconnect_attempts = 0
def display_reconnecting(self):
self.ax.clear()
self.ax.text(0.5, 0.5, f"Reconnecting...\nAttempt {self.reconnect_attempts}/{self.max_reconnect_attempts}",
ha='center', va='center', color='yellow')
self.canvas.draw()
self.equity_label.configure(text="Reconnecting...", fg='yellow')
self.change_from_purchase_label.configure(text="", fg='yellow')
self.change_label_today.configure(text="", fg='yellow')
def display_connection_error(self):
self.ax.clear()
self.ax.text(0.5, 0.5, "Connection lost.\nUnable to fetch data.\nPlease check your internet connection.",
ha='center', va='center', color='red')
self.canvas.draw()
self.equity_label.configure(text="Connection Error", fg='red')
self.change_from_purchase_label.configure(text="", fg='red')
self.change_label_today.configure(text="", fg='red')
I don't think my root cause was the same as your but if you use custom DNS server (for example pihole) fc.yahoo.com could be blocked. So ensure you can open and connect to the url from the device and you may check your dns.
Yes, I use unbound on router and when I connect to fc.yahoo.com it redirects to https://www.yahoo.com/. I tested with the script below (see response). But I don't think unbound is the problem as my scripts work fine on Linux OS.
import requests
def check_connection(url): try:
response = requests.get(url, timeout=10) # Set a timeout to prevent hanging
# Check if the response status code is 200 (OK)
if response.status_code == 200:
print(f"Successfully connected to {url}.")
else:
print(f"Failed to connect to {url}. HTTP Status Code: {response.status_code}")
except requests.exceptions.Timeout:
print(f"Connection to {url} timed out.")
except requests.exceptions.RequestException as e:
print(f"Failed to connect to {url}. Error: {e}")
url_to_check = "fc.yahoo.com"
check_connection(url_to_check)
Failed to connect to https://fc.yahoo.com. HTTP Status Code: 404
Describe bug
1 Failed download: ['UPRO']: ConnectionError(MaxRetryError('HTTPSConnectionPool(host=\'fc.yahoo.com\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x000001AD4DB41FD0>: Failed to resolve \'fc.yahoo.com\' ([Errno 11001] getaddrinfo failed)"))'))
This happens for all tickers. UPRO is just an example.
Simple code that reproduces your problem
import yfinance as yf import pandas as pd
def fetch_data(tickers): ticker_data = {} for ticker in tickers: try: data = yf.download(ticker, 5d, 1m, threads=True) if not data.empty: ticker_data[ticker] = data['Close'] else: ticker_data[ticker] = None except Exception as e: ticker_data[ticker] = None return ticker_data
def update_data(tickers): ticker_data = fetch_data(tickers)
def run_script(): tickers = ["UPRO"] update_data(tickers)
if name == "main": run_script()
Debug log
1 Failed download: ['UPRO']: ConnectionError(MaxRetryError('HTTPSConnectionPool(host=\'fc.yahoo.com\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x000001AD4DB41FD0>: Failed to resolve \'fc.yahoo.com\' ([Errno 11001] getaddrinfo failed)"))'))
[*****100%%**] 1 of 1 completed
1 Failed download: ['UPRO']: ConnectionError(MaxRetryError('HTTPSConnectionPool(host=\'fc.yahoo.com\', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x000001AD4DC65A10>: Failed to resolve \'fc.yahoo.com\' ([Errno 11001] getaddrinfo failed)"))'))
Bad data proof
No response
yfinance
version0.2.41
Python version
3.11
Operating system
WIN11