urlread - IP address could not be determined

5 views (last 30 days)
Hi team
I am using EODHD.COM for stock data. I get the following error every now and then. example - if I am iterating over say 50 stocks data, the code sometimes throw an error for 1 stock, then I rerun the full script allover again and it will work. I used webread to start with but webread doesn't even read the webpage and returns no data (urlread returns data instead).
Error using urlreadwrite_legacy (line 88)
The IP address of "eodhd.com" could not be determined.
Error in urlreadwrite (line 88)
[output,status] = urlreadwrite_legacy(fcn,catchErrors,varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in urlread (line 16)
[s,status] = urlreadwrite(mfilename,catchErrors,url,varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in NSE_all (line 78)
EOD_data = urlread(URL2); % json data
^^^^^^^^^^^^^
My codes are:
url2A = 'https://eodhd.com/api/eod/';
url2B = '?from=';
url2C = '&period=d&api_token=';
url2D = '&fmt=json';
From = datetime("today") - (365 * 20);
dt_str = char(From);
URL2 = url2A + company + url2B + dt_str + url2C + token + url2D;
EOD_data = urlread(URL2);
*please note company is a name of the stock ticker I take from the list for the For loop so I iterate through multiple companies stocks.
Is it possible to tell urlread to wait longer and try more before throwing an error? or even keep trying for the specified time? I want urlread to not stop my script at any random time. I am new to Matlab so if anyone can help it would be great.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Jan 2025
urlread accepts a Timeout option
However, the Timeout is on reading data only. There is no option for telling urlread to retry unsuccessful connections.
Note: urlread() is not longer recommended. It is recommended that you switch to webread instead.
  1 Comment
Amit Patel
Amit Patel on 30 Jan 2025
thanks Walter. I would have appreciated bit more help on why webread() returns no data whereas urlread() returns data. I am not using any other arguments inside the brackets other than the url itself. Also to continue after the https errors I will introduce try catch into my codes too.

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!