Forums

yfinance stopped working

I have a script that fetched financial data from yfinance, it have been working fine for the past 6 months, then suddenly out of nowhere, yesterday stoped working. Even if delete all lib and reinstall yfinance when i try to just run this command from console shell: python -c "import yfinance as yf; print(yf.download('BTC-USD'))" I get this error:

12:36 ~/mysite $ python -c "import yfinance as yf; print(yf.download('BTC-USD'))" Failed to get ticker 'BTC-USD' reason: Expecting value: line 1 column 1 (char 0) [***100%*****] 1 of 1 completed 1 Failed download:

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

But on my local computer it works just fine and it does fetch data... so what im doing wrong?

I'm getting this issue too, and the issue is also on yahoo_fin. So the problem is shared across those tools!

The problem is that finance.yahoo.com is not on the allowlist anymore https://www.pythonanywhere.com/whitelist

Any chance you guys at pythonanywhere.com can add finance.yahoo.com in order for yfinance lib to work again?

No, that is not the problem. .yahoo.com is on the allowlist and that includes finance.yahoo.com. You will need to see what you are getting back from finance.yahoo.com in order to see what the problem is.

this is what im getting Pythonanywhere server console

and this is from my local PC

My local PC shell

my bad the image from missing module error is incorrecy, here is the correct image im obtaining from yfinance call

Pythonanywhere console on yfinance lib

unfortunatelly its confirmed that pythonanywhere.com is blocking calls made from yfinance lib causing the script to stop working.

I hope someone from support is reading, cause i got a reply 10 hours ago from Samuel from support, but then a silenece and i need to keep using my code

here is the proof of what im claiming, run this command from console:

python -c "import yfinance as yf; print(yf.download('BTC-USD'))"

And you will get failed download error, while if you do it from any other server you will be sucessful

created a new test account, and this new test account was able to fetch data without problem using this command from console from yfinance

python -c "import yfinance as yf; print(yf.download('BTC-USD'))"

So i guess ill have to request an account delete and restart again... isnt there a way to do this from dashboard than having to send email? Thanks

is not working anymore.... Again

cant call this command to fetch simple data from console:

python -c "import yfinance as yf; print(yf.download('BTC-USD', start='2024-01-01', end='2024-10-09'))"

If someone from support is reading, please help, as i have no idea what else it could be causing this network blocking

Add me to the list of users wanting Yahoo Finance to work!

I just got my first app deployed on Monday and now I'm....well you know.... stuck. This, of course places, my joining the PythonAnywhere folks in jeopardy.

Let's hope PythonAnywhere this can be fixed ASAP.

i have the same problem:

2024-10-10 04:50:30,782: Failed to get ticker 'POWL' reason: Expecting value: line 1 column 1 (char 0)

We are not blocking yahoo. It looks like yahoo is returning something else then what that library is expecting.

then how comes on local machines everything works fine? I understand that if yahoo is returning something else and the fault is in library JSONDecoder expecting something else, we should have that problem too given we have all the same library version. Moreover, the problem seems to be shared across libraries: both yahoo_fin and yfinance

EDIT: I also tried updating libraries on pythonanywhere bash console but didn't work! for my particular project I decided to implement a mechanism where whenever yfinance does not work I fall back on other sources through API Call (open-exchange rate api to be specific)

I am having the same issue with yfinance calls ..PA support staff please sort this out!

Good point on that yFinance works from a local desktop.

I noticed about a month ago, if I had turned on my local VPN service (ExpressVPN), I was getting the following error when checking for the short name: sShortName = df.info['shortName']

Traceback (most recent call last): File "c:....\Yahoo.py", .... sShortName = df.info['shortName'] File "c:....\Python\Python39\lib\site-packages\yfinance\ticker.py", line 159, in info return self.get_info() File "c:....\Python\Python39\lib\site-packages\yfinance\base.py", line 229, in get_info data = self.quote.info File "c:....\Python\Python39\lib\site-packages\yfinance\scrapers\quote.py", line 508, in info self._fetch_info(self.proxy) File "c:....\Python\Python39\lib\site-packages\yfinance\scrapers\quote.py", line 598, in _fetch_info result = self._fetch(proxy, modules=modules) File "c:....\Python\Python39\lib\site-packages\yfinance\scrapers\quote.py", line 587, in _fetch result = self._data.get_raw_json(_QUOTE_SUMMARY_URL + f"/{self._symbol}", user_agent_headers=self._data.user_agent_headers, params=params_dict, proxy=proxy) File "c:....\Python\Python39\lib\site-packages\yfinance\data.py", line 398, in get_raw_json response = self.get(url, user_agent_headers=user_agent_headers, params=params, proxy=proxy, timeout=timeout) File "c:....\Python\Python39\lib\site-packages\yfinance\utils.py", line 104, in wrapper result = func(args, kwargs) File "c:....\Python\Python39\lib\site-packages\yfinance\data.py", line 366, in get response = self._session.get(request_args) File "c:....\Python\Python39\lib\site-packages\requests\sessions.py", line 602, in get return self.request("GET", url, kwargs) File "c:....\Python\Python39\lib\site-packages\requests\sessions.py", line 589, in request resp = self.send(prep, send_kwargs) File "c:....\Python\Python39\lib\site-packages\requests\sessions.py", line 703, in send r = adapter.send(request, *kwargs) File "c:....\Python\Python39\lib\site-packages\requests\adapters.py", line 501, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

pip show yfinance (current version of yfinance) Name: yfinance Version: 0.2.44

This looks like a firewall issue at PA's whether it be something Yahoo or PA. What is confusing is that it sometimes works if my VPN and sometimes not. (Hence PA's response that it works for them.)

Bottomline is, turning off/on VPN from my local desktop causes it to fail thus pointing to a firewall issue.

To support that though is using Google Chrome and after a search clicking on an search item, if VPN is turned on, Google Click services fail. (Their ad services.) Turning off VPN it works. ExpressVPN says Google is block (or failing) because too many requests are coming from a single IP address. Wonder if this could be the same issue with Yahoo?

Hope this helps.

To support that thought is using Google Chrome and after a search clicking on a search item, if VPN is turned on, Google Click services fail. (Their ad services.) Turning off VPN it works. ExpressVPN says Google is block (or failing) because too many requests are coming from a single IP address. Wonder if this could be the same issue with Yahoo?

i think we can run our python script as backup alternative to the PA issue with yfinance using Vercel

This is not something that we can do anything about - it's 2 libraries that we have no control over accessing a site that we have no control over.

IMHO the best thing to do is look for a workaround, if any are available. For the PA staff - could you at least clarify why on local machines it does seem to work while why on PA it looks like it does not, across 2 libraries that both access the same underlying service? Even if you have no idea why, just knowing it can surely help mitigate panic hahahah.

The An existing connection was forcibly closed by the remote host error posted by @jaberdeen suggests that it's some sort of blocking applied by yahoo.

yes, i think Yahoo is blocking PA IPs or domain

PA -( Glenn) - Not sure that is a 100% correct assessment that Yahoo is blocking. If Yahoo was blocking the calls, then all calls using yfinance.py deployments around the world would fail. This not the case for local calls to Yahnoo work just fine. In other words, it is not yfinance.py version 2.4.4 - latest version and it's libraries. (Not a software issue.)

Let's review what we know:

  1. The 2 libraries have not changed. Tuesday night, my app was working and suddenly it wasn't. There were no new deployments of new libraries so let's remove that from being a potential problem.
  2. For the calls to suddenly fail, this means something has change either at Yahoo, PA or somwhere else.
  3. If Yahoo implemented a change, then it had to be targeted to companies like PA blocking multiple calls to Yahoo by blocking IP addresses. This would explain why it works from our desktops and not PA. (Assuming the end user is not using any VPN service adding a layer of complexity.) Yahoo may have Whitelisted PA to block calls. PA needs to find out.
  4. The other scenario is PA (or their cloud provider) made a firewall change to block outgoing and/or incoming responses from Yahoo. PA needs to investigate.

The reason the thinking it is a firewall issue is that in my experience deploying software applications in-house and to the public for many years is that a majority of the time is that it was a firewall issue done by someone between the various network layers. (Yahoo, PA, cloud provider, etc.)

And so, is PA continuing to work on this issue or have decided and/or closed the issue?

So further research on yfinance.py errors - (last line of my earlier posts) suggest the following: The error message ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)) typically indicates that the connection to the remote server was unexpectedly closed. This can happen for several reasons, including:

Network Issues: - There might be network connectivity problems between your client and the server. (PA and Yahoo) - Server-Side Blocking: The server might be blocking your IP address or the specific request. (Yahoo is blocking. PA needs to find out.) - Firewall Restrictions: Firewalls on either the client or server side might be interrupting the connection. (Again PA and/or Yahoo) - Rate Limiting: The server might be rate-limiting requests from your IP address if it detects too many requests in a short period. (Yahoo is blocking PA because of IP addresses)

In the context of PythonAnywhere, users have reported similar issues when trying to fetch data from Yahoo Finance using libraries like yfinance.This could be due to Yahoo Finance’s server blocking requests from certain IP addresses or due to changes in the website’s structure that affect the library’s ability to fetch data.

Going forward: Check your network connection to ensure it’s stable. Verify if the server is blocking your IP by trying the same request from a different network. (This would explain why it works from local IP addresses)

From my perspective, it doesn't seem like PA is doing anything about this specific case. I believe it's a firewall setting on PA's side, not Yahoo blocking it. However, based on what I've read, PA appears to be avoiding responsibility for this issue, which isn't reflective of good business practices.

Some services block access from non-domestic sources (like headless servers in data centers). That could be the case.

just as a heads up this morning again yfinance was working

Yes...confirmed that yfinance is now working!! Any idea how it was resolved?

Not sure who takes credit, but certainly thanks are in order to Glenn (PA) for your assistance in listening to us users.

Well, it's down again... I switched to another provider, but it required me to redo 70% of the new code because of it

Cyptobotforex - Who are you moving to? Thx!

it's down again ; pa please help on this.

We can't do anything about an external service, unfortunately.