今日已更新 74 条资讯 | 累计 28386 条内容
关于我们

yfinance NG=F Not Working? Why Natural Gas Futures Data Fails and 3 Fixes That Work

Synergic-Apis 2026年07月31日 17:44 5 次阅读 来源:Dev.to

If your script suddenly started printing this: >>> import yfinance as yf >>> df = yf . download ( " NG=F " , period = " 1mo " ) 1 Failed download : [ ' NG=F ' ]: YFPricesMissingError ( ' possibly delisted; no price data found ' ) …you didn't break anything. NG=F (the natural gas futures ticker on Yahoo Finance) periodically stops returning data for everyone, and futures tickers get hit harder than stocks. This post covers why it happens and the three fixes that actually work, ordered from "quick patch" to "never deal with this again." 1. What the error actually means yfinance is not an official API . It's a (great) community library that scrapes Yahoo Finance's internal endpoints — the same ones Yahoo's own website uses. Yahoo doesn't document them, doesn't promise they'll keep working, and changes them whenever it suits their frontend. When Yahoo changes something — an endpoint, a rate limit, a response format — yfinance breaks until its maintainers reverse-engineer the change. Futures symbols like NG=F and GC=F are the most fragile: they've had recurring gaps and failures reported over the years, for example #2620 (missing recent data for NG=F/GC=F) , #2635 (whole missing days in futures history) and the evergreen #865 "Futures only work sometimes" . So: "possibly delisted" almost never means delisted. It means "the scrape came back empty." 2. Fix #1 — the quick patches (works today, breaks tomorrow) Three things fix most transient failures: Upgrade first. The maintainers usually patch Yahoo changes within days: pip install -U yfinance Retry with backoff. Failures are often intermittent rate-limiting, not hard breaks: import time import yfinance as yf def download_with_retry ( ticker , retries = 3 , wait = 5 , ** kwargs ): for attempt in range ( 1 , retries + 1 ): df = yf . download ( ticker , progress = False , ** kwargs ) if not df . empty : return df print ( f " attempt { attempt } came back empty, retrying in { wait } s… " ) time . sleep ( wait * attempt ) rai

本文内容来源于互联网,版权归原作者所有
查看原文