Why do I get 403 message when trying to download stock historical data from yahoo from 3/5/21? Before works
3 views (last 30 days)
Show older comments
Hi,
I always use [temp, status] = urlread(url) to get data from yahoo.
For example here is what I used.
t1 = strcat('https://query1.finance.yahoo.com/v7/finance/chart/AAPL?range=3y&interval=1d&indicators=quote&includeTimestamps=true');
[temp, status] = urlread(t1)
Last Friday I tried to use this same, but all return w/ 0.
I tried to use webread as Matlab recommended, but got the following error message, can you help here? Thanks,
t1 = strcat('https://query1.finance.yahoo.com/v7/finance/chart/AAPL?range=3y&interval=1d&indicators=quote&includeTimestamps=true');
data = webread(t1)
Error message:
Error using readContentFromWebService (line 46)
The server returned the status 403 with message "Forbidden" in response to the request to URL
https://query1.finance.yahoo.com/v7/finance/chart/AAPL?range=3y&interval=1d&indicators=quote&includeTimestamps=true.
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
How should I use?
2 Comments
Michael
on 14 Mar 2021
Intereting ... I am getting the same error message from code that used to work fine a couple of months ago. Did something change on Yahoo side?
Anthony John
on 29 Mar 2021
Same for me. Have either of you found a solution? Yahoo's URL appears unchanged.
Answers (1)
Ralph N
on 16 Jun 2021
Two things changed: (1) they updated the URL (2) they limit particular user agents (Matlab is explicitly rejected)
The URL as of 6/16/2021 is:
symbolString = 'TGT'; % look up Target prices as an example
urlBase = 'https://query1.finance.yahoo.com/v7/finance/download/'; % base as of 6/16/2021
url = [urlBase,symbolString];
Then we explicitly set the user agent:
options = weboptions('UserAgent',''); % as of 6/16/2021 it is enough to submit a blank user agent
1 Comment
James morgenstern
on 16 Aug 2021
Ralph N -- I could kiss you! I have struggled with this one for months ... I read that Yahoo changed their interface to prevent, among other things my trying to read some finance info tables. This solved the problem: Many thanks.
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!