yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

TypeError: argument of type 'NoneType' is not a container or iterable in _fetch_info

Open savojosh opened this issue 5 months ago • 2 comments

Describe bug

_fetch_info crashes with a TypeError when both _fetch() and _fetch_additional_info() return None. The assignment on line 625 sets result = additional_info (i.e. None), and then line 629 performs a membership test on it:

# quote.py lines 622–629
if additional_info is not None and result is not None:
    result.update(additional_info)
else:
    result = additional_info  # result is now None if both fetches returned None

...
if quote in result and ...  # TypeError: argument of type 'NoneType' is not iterable

Every other _fetch call in the file guards with if result is None: return before proceeding, so this looks like an oversight specific to _fetch_info.

The issue reproduces when requests are routed through a custom session (e.g. a proxy) that receives a null/blocked response from Yahoo. Direct connections return valid data for the same tickers, so the None path is only reachable when Yahoo returns an empty payload.

Simple code that reproduces your problem

import yfinance as yf
from curl_cffi import requests as curlRequests

# Proxy or any session that causes Yahoo to return a null payload
session = curlRequests.Session(impersonate="chrome", proxies={"http": "<proxy>", "https": "<proxy>"})

ticker = yf.Ticker("NPCE", session=session)
info = ticker.info  # raises TypeError

Direct call (no session) succeeds for the same tickers — the None path is only hit when the session causes Yahoo to return a null result field.

Debug log with debug logging enabled

yf.config.debug_logging = True
File ".../yfinance/scrapers/quote.py", line 629, in _fetch_info
    if quote in result and len(result[quote]["result"]) > 0:
       ^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable

Bad data proof

N/A — this is a crash, not incorrect data.

yfinance version

1.4.1

Python version

3.14

Operating system

Windows 11

savojosh avatar Jun 17 '26 18:06 savojosh

I opened a PR that fixes this here: https://github.com/ranaroussi/yfinance/pull/2869

The fix handles the None response path in _fetch_info() by normalizing result to {} when _fetch() returns None, and only merging additional_info when it is not None.

I also tested the original crash path by monkeypatching both internal fetch methods to return None. Before the fix, it raised:

TypeError: argument of type 'NoneType' is not a container or iterable

After the fix, it no longer crashes.

parthdongre avatar Jun 22 '26 06:06 parthdongre

@ Appears fixed on dev. _fetch_info now guards if result is None: result = {} and reads via result.get(quote, {}).get("result", []) instead of the if quote in result membership test that raised the TypeError. The path where both _fetch() and _fetch_additional_info() return None no longer crashes. Appears safe to close. @

DogInfantry avatar Jul 08 '26 08:07 DogInfantry