Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectionError #2024

Open
BeachGuy007 opened this issue Aug 13, 2024 · 23 comments
Open

ConnectionError #2024

BeachGuy007 opened this issue Aug 13, 2024 · 23 comments

Comments

@BeachGuy007
Copy link

BeachGuy007 commented Aug 13, 2024

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)

for ticker, data in ticker_data.items():
    if data is not None and len(data) > 0:
        latest_price = data.iloc[-1]
    else:
        latest_price = 'N/A'

df = pd.DataFrame(data_rows, columns=["Ticker", "Price"])

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 version

0.2.41

Python version

3.11

Operating system

WIN11

@BeachGuy007
Copy link
Author

Mysteriously working now

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 14, 2024

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.

@BeachGuy007
Copy link
Author

Happened again this morning. All quotes N/A

@BeachGuy007 BeachGuy007 reopened this Aug 21, 2024
@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

Working now. I guess intermittent issue? Could be Yahoo servers?

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

Happening again (5am). Issue with Yahoo servers? Throttling?

@ValueRaider
Copy link
Collaborator

Are you spamming? #1513

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

Ah no. Real issue. Worked fine all day yesterday. Worked this morning for a while then N/A now.

@BeachGuy007
Copy link
Author

Now some quotes coming through. I think it's yahoo servers(?).

@ValueRaider
Copy link
Collaborator

ValueRaider commented Aug 21, 2024

yfinance stores cookie here: https://github.com/ranaroussi/yfinance#persistent-cache-store - does deleting it help?

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

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")

@BeachGuy007
Copy link
Author

All quotes were N/A a second ago and just now flashed real quote.

@ValueRaider
Copy link
Collaborator

I also don't have yf.set_tz_cache_location

... how did you check yfinance version?

@BeachGuy007
Copy link
Author

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: [email protected]
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>

@ValueRaider
Copy link
Collaborator

PIP can be wrong. Use the method in the new issue form.

@BeachGuy007
Copy link
Author

Back to N/As again

@BeachGuy007
Copy link
Author

import yfinance as yf ; print(yf.version)
0.2.41

@ValueRaider
Copy link
Collaborator

ValueRaider commented Aug 21, 2024

Regardless, if you don't have yf.set_tz_cache_location then your version must be almost 1-year old or corrupt. 59af19d

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

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

@ValueRaider ValueRaider closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
@BeachGuy007
Copy link
Author

New error even after uninstalling/reinstalling.

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

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

@BeachGuy007
Copy link
Author

Maybe it's their severs? Right at 9:30am all quotes worked today.

@BeachGuy007
Copy link
Author

BeachGuy007 commented Aug 21, 2024

1/2 an hour into the trading day and all quotes working fine. Must be something sporadic with Yahoo servers during ETH.

@BeachGuy007
Copy link
Author

BeachGuy007 commented Oct 23, 2024

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants