Forums

Yfinance not working Please advise

Hi, I’m on a paid PythonAnywhere account (username: ghanagirl). I’m trying to use yfinance to download stock data. The same code works on my local Windows machine, but on PythonAnywhere it always returns an empty DataFrame with a JSONDecodeError.

Here’s the exact test I ran from a Bash console inside my virtualenv:

import yfinance as yf print("Trying to download NVDA 1h data...") try: df = yf.download("NVDA", period="5d", interval="1h") print("Empty dataframe?:", df.empty) print(df.head()) except Exception as e: print("ERROR:", repr(e))

And here is the output:

Trying to download NVDA 1h data... Failed to get ticker 'NVDA' reason: Expecting value: line 1 column 1 (char 0) [***100%*****] 1 of 1 completed 1 Failed download:

Empty dataframe?: True Empty DataFrame Columns: [Open, High, Low, Close, Adj Close, Volume] Index: []

Could you please let me know if there’s an issue with yfinance/Yahoo requests from PythonAnywhere servers, or if there’s a recommended workaround (proxy, headers, or alternate endpoint)?

Thank you!

We have no control over the defences that Yahoo place against scraping their site. It's possible that they block requests from AWS (where our servers are hosted). You could use a proxy of some sort to work around that, it you like.