yfinance: ConnectionError

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26

Most upvoted comments

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.