ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.02k stars 2.31k forks source link

Yfinance Intermittently working #1111

Closed locfinessemonster closed 1 year ago

locfinessemonster commented 1 year ago

I have used yfinance for a while using a very old mac and haven't had any problems. I recently upgraded my computer to Windows 11 and am trying to run basic yfinance functions like yf.download in jupyter notebook on a chrome browser and I keep gettting the error message "No data found for this date range, symbol may be delisted" as well as error 10060. I have tried downgrading to older library versions and using the "pip install yfinance --upgrade --no-cache-dir" recommended fix but I am still getting this problem. The workaround I came up with is to keep retrying the yf.download and sleeping for a couple seconds if it fails. It seems to eventually download after around 10 tries or so but this doesn't seem to be the most elegant solution. I have tried changing my firewall settings and it doesn't seem like my computer is blocking anything. I am pretty stumped, if you have any suggestions I would really appreciate it!

locfinessemonster commented 1 year ago

Code with errors that I am seeing: image image

locfinessemonster commented 1 year ago

Work around code: image

locfinessemonster commented 1 year ago

Longer sleep interval between requests seems to help me get it with less requests, still a mystery as to why I consistently can't get it on the first try. image

ValueRaider commented 1 year ago

Did you try 0.1.74 or older?

jordangrodecki commented 1 year ago

Also had this bug after building a new venv - spent ages before dropping back to 0.1.74 which works fine.

ValueRaider commented 1 year ago

We think we know why (related to #1076) and plan a release very soon.

locfinessemonster commented 1 year ago

Also had this bug after building a new venv - spent ages before dropping back to 0.1.74 which works fine.

I tried pip install yfinance==0.1.7.4 and still got the same issue. Tried yfinance==0.1.67 and got the same error

locfinessemonster commented 1 year ago

We think we know why (related to #1076) and plan a release very soon.

Awesome, thank you for the update.

ValueRaider commented 1 year ago

Also had this bug after building a new venv - spent ages before dropping back to 0.1.74 which works fine.

I tried pip install yfinance==0.1.7.4 and still got the same issue. Tried yfinance==0.1.67 and got the same error

Oh, if you have same problem with 0.1.74 or older then no, that needs investigation. What version was on your Mac?

locfinessemonster commented 1 year ago

Also had this bug after building a new venv - spent ages before dropping back to 0.1.74 which works fine.

I tried pip install yfinance==0.1.7.4 and still got the same issue. Tried yfinance==0.1.67 and got the same error

Oh, if you have same problem with 0.1.74 or older then no, that needs investigation. What version was on your Mac?

I was using version 0.1.74 on my Mac and never ran into many issues. I tried running a Beautiful Soup Scraper on my Windows 11 machine, and I got error #10060 from that as well and that code never had any problems either on my old Mac. I wonder if I somehow got blacklisted by yfinance? I don't think I really ever sent too many requests yfinance though which seems odd. image

ValueRaider commented 1 year ago

Any blacklisting is very temporary, so rolling back to 0.1.74 should have eventually restored normal behaviour.

For 0.1.75 and later, a release went out yesterday that should resolve problem.

locfinessemonster commented 1 year ago

Built both the yf v0.1.83 and v0.1.84 from the tar.gz files released yesterday and still having same issues unfortunately.

ValueRaider commented 1 year ago

Ok thanks for feedback on 0.1.84, but did rolling back to 0.1.74 solve?

Does the for w in range loop with sleep removed always encounter your error? If yes, how many iterations?

What is the actual loop you are trying to run?

What happens if you run in command line shell instead of Jupyter?

locfinessemonster commented 1 year ago

Did rolling back to 0.1.74 solve? No, still getting same errors with 0.1.74 Does the for w in range loop with sleep removed always encounter your error? If yes. how many iterations? Yes, it pretty typically does, the standard range of iterations pretty typically seems to be between 2 and 10 image What is the actual loop you are trying to run? The actual loop I am trying to run is trying to collect minutely price movement data for a list of stocks generally around 75 stocks long and export to csv. image What happens if you run in command line shell instead of Jupyter? Running from command line using a virtual environment with yfinance==0.1.74 installed still gives me the same errors I have been seeing image

ValueRaider commented 1 year ago

Curious that this only started with Windows, but the typical cause of these errors is spamming Yahoo with 100s requests/day - are you? If only running 1-2 times/day then unlikely to be Yahoo, which implies a Windows problem.

The solution to rate limiting is stop spamming Yahoo for data you could cache locally. Caching solutions:

locfinessemonster commented 1 year ago

Since this code has not been working properly, I haven't been running it at all outside of trying to debug yfinance. It's definitely a bit odd, I was thinking it was maybe my internet or firewall or something but I have some similar code that requests data from the WeBull API and it has been running without any problems.

I gave requests_cache a shot and still no luck. image

I gave yfinance_cache a shot as well still getting an error image

Do you think rolling back my os to Windows 10 could potentially fix the issues I am having?

ValueRaider commented 1 year ago

That last error looks like a Windows networking issue. Maybe start with Googling 10060 error code

locfinessemonster commented 1 year ago

I had some old tor code that I used to set a proxy on yf.download and now it seems as if everything is consistently working. image

ValueRaider commented 1 year ago

If you don't mind, I'll tag this issue as "Windows" and close. I know Tor isn't ideal but I don't see what yfinance can do.

locfinessemonster commented 1 year ago

That sounds good, thanks for your help!