pandas-datareader icon indicating copy to clipboard operation
pandas-datareader copied to clipboard

YahooOptions not working properly

Open tachyon-ops opened this issue 3 years ago • 2 comments

So, I have tried to request options and calls using

import pandas_datareader.data as web

FB = web.YahooOptions('FB')
print(FB.expiry_dates)

which yields

pandas_datareader._utils.RemoteDataError: Unable to read URL: https://query1.finance.yahoo.com/v7/finance/options/FB
Response Text:
b'Forbidden'

Now, accessing that URL from the browser works fine. So I then tried to do a simple 'requests' get. It turned out:

response = requests.get("https://query1.finance.yahoo.com/v7/finance/options/FB")
print(response.text)

yields

Forbidden

But if I add headers

headers = {'User-Agent': 'Firefox'}
response = requests.get(
    "https://query1.finance.yahoo.com/v7/finance/options/FB", headers=headers).json()

I get the proper response. Calls work the same...

Therefore, I think Yahoo is constraining its api no?

tachyon-ops avatar Jan 06 '22 10:01 tachyon-ops

Hello,

I had the same problem. Apparently, the API is refusing requests without headers.

My workaround was to add the headers directly to the object.

Also, the ticket FB is returning blank because it got change to 'META'

FB = web.YahooOptions('FB')
FB.headers = {'User-Agent': 'Firefox'}
print(FB.expiry_dates)

It would be nice to have a default header for that request IMO.

Hope it helps :)

Victorhpinheiro avatar Sep 20 '22 22:09 Victorhpinheiro

change FB by META

kamel003 avatar Feb 23 '23 14:02 kamel003