Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YahooOptions not working properly #923

Open
tachyon-ops opened this issue Jan 6, 2022 · 2 comments · May be fixed by #924
Open

YahooOptions not working properly #923

tachyon-ops opened this issue Jan 6, 2022 · 2 comments · May be fixed by #924

Comments

@tachyon-ops
Copy link

tachyon-ops commented Jan 6, 2022

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 tachyon-ops linked a pull request Jan 6, 2022 that will close this issue
5 tasks
@Victorhpinheiro
Copy link

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 :)

@kamel003
Copy link

change FB by META

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants