holzschu / Carnets

Carnets is a stand-alone Jupyter notebook server and client. Edit your notebooks on the go, even where there is no network.
https://holzschu.github.io/Carnets_Jupyter/
BSD 3-Clause "New" or "Revised" License
568 stars 33 forks source link

read URL yahoo finance #276

Closed KenziTrader closed 1 year ago

KenziTrader commented 1 year ago

I try to read an options chain from yahoo finance with pandas_datareader. Reading the URL fails with b'Forbidden'. I can open the URL in Safari.

Do I need to do something special to give Carnets permission to open an URL?

Thanks, Rene

image

holzschu commented 1 year ago

Carnets and Pandas can open URLs, so I think your problem is specific to Yahoo Finance.

Looking at open issues in pandas_datareader, I see this one, which is very similar: https://github.com/pydata/pandas-datareader/issues/923 There is even a suggested fix:

FB = web.YahooOptions('FB')
FB.headers = {'User-Agent': 'Firefox'}
print(FB.expiry_dates)
KenziTrader commented 1 year ago

Yes, thanks, setting the user agent works.