You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pandas_datareader获取美股数据遇RemoteDataError求助

Fixing RemoteDataError for Stock Price Retrieval

Why You're Getting the Error

The error pops up because Google Finance discontinued its historical data API years ago—so the 'google' data source in pandas_datareader is no longer functional. The URL your code tries to access (http://www.google.com/finance/historical?q=...) is completely inactive now, hence the RemoteDataError.

Quick Fix: Use yfinance Instead

yfinance is a well-maintained library built specifically to replace the defunct Google Finance data feed. Here's how to adjust your code (plus I fixed a typo: MFST → MSFT for Microsoft's ticker):

  1. First install yfinance via pip:
pip install yfinance
  1. Update your code to use yfinance:
import yfinance as yf
from datetime import datetime

tech_list = ['AAPL', 'GOOG', 'MSFT', 'AMZN']
end = datetime.now()
start = datetime(end.year-1, end.month, end.day)

# Fetch all stock data in one go (more efficient than looping)
all_stock_data = yf.download(tech_list, start=start, end=end)

# If you still want individual DataFrames stored in global variables (matching your original approach)
for stock in tech_list:
    globals()[stock] = all_stock_data.xs(stock, level=1, axis=1)

Alternative: Stick with pandas_datareader (Using yfinance Adapter)

If you prefer keeping the pandas_datareader syntax, you can enable its yfinance adapter:

from pandas_datareader import data
from datetime import datetime
import yfinance as yf

yf.pdr_override()  # Lets pandas_datareader use yfinance under the hood

tech_list = ['AAPL', 'GOOG', 'MSFT', 'AMZN']
end = datetime.now()
start = datetime(end.year-1, end.month, end.day)

for stock in tech_list:
    globals()[stock] = data.DataReader(stock, start=start, end=end)

Quick Tip

Always double-check stock tickers—MFST is not a valid ticker for Microsoft; the correct one is MSFT.

内容的提问来源于stack exchange,提问作者Nikhil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:30:26