Hello,
I’m trying to get the datas from an etf with yfinance using this code :
import yfinance as yf
import pandas as pd
import streamlit as st
# Define start and end dates for fetching data
start_date = "2022-06-01"
end_date = pd.Timestamp.today().strftime("%Y-%m-%d")
# List of ISINs or ticker symbols
list_isin = ["JP3049040003"]
# Initialize lists to store data
prices_data = []
names_data = []
# Fetch data for each ISIN or ticker symbol
for isin in list_isin:
try:
# Fetch stock info and closing prices
stock_info = yf.Ticker(isin).info
name = stock_info['shortName']
df = yf.download(isin, start=start_date, end=end_date, progress=False)["Close"]
# Append data to lists
names_data.append(name)
prices_data.append(df)
except Exception as e:
st.write(f"Error fetching data for {isin}: {e}")
# Concatenate data into a DataFrame
if prices_data:
df_stocks = pd.concat(prices_data, axis=1)
df_stocks.columns = names_data
# Plot cumulative returns
cumulative_returns = (1 + df_stocks.pct_change(fill_method='ffill')).cumprod()
st.line_chart(cumulative_returns)
else:
st.write("No data available to plot.")
When I use the code on my computer everything is good but when i do it on my shared app online i got this error message :
“Failed to parse json response from Yahoo Finance: {‘code’: ‘Not Found’, ‘description’: ‘HTTP 404 Not Found’}”
I asked Chatgpt about it and the answer was :
Streamlit applications might have restrictions on external API access compared to your local environment. Some APIs might block requests coming from shared hosting environments to prevent misuse.
I found out later that it works if enter the ticker (2563.T) but not if I enter the ISIN (JP3049040003) so I can’t understand why this answer could be right.
If someone can find an explanation, I would be grateful!