Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave urlread will not download data due to "Pee

Tags:

octave

urlread

I am using Octave 4.0.0 for windows, and want to download stock prices from a web page that is open to all public. I use the following call:

data = urlread(https://www.netfonds.no/quotes/paperhistory.php?paper=API.A&csv_format=csv)

However, I get the following error message:

urlread: Peer certificate cannot be authenticated with given CA certificates

I have searched internet, including StackOverflow, for this error message, but do not understand the advices given there.

Q1: Is there something lacking on my pc? If so, what do I do?
Q2: Can I change the call somehow to adjust for something lacking on my pc?

Thanks in advance for any help : )

like image 529
myotis Avatar asked Feb 10 '23 22:02

myotis


2 Answers

It appears that is a bug in urlread() for certain versions of Octave. For a course I'm doing, we changed this:

responseBody = urlread(submissionUrl, 'post', params);

to

[code, responseBody] = system(sprintf('echo jsonBody=%s | curl -k -X POST -d @- %s', body, submissionUrl));

like image 69
cynod Avatar answered Feb 12 '23 11:02

cynod


Although the page is publicly available, the connection is encrypted. For an encrypted connection to make sense, it must use a key that you trust. The typical user does not thinks about whether to trust it, it leaves the job of deciding this to the OS or web browser (who then rely on certificate authorities). I am guessing this is your case.

The error you get is because the website you are accessing uses a key that was certified by something that urlread does not "trust". Ideally, you would have a single list of trusted certificates and all applications would use it. If your web browser trusts it, but the rest of your system does not, you have a configuration issue. Either your web browser is keeping its own list of trusted certificates, or libcurl (the library that urlread uses) is not finding the certificates installed on your system.

This "configuration" will be a directory with several .pem files. The specific certificate required for this website will most likely be named GlobalSign_Root_CA_-_R2.pem.

And it works here:

octave> data = urlread ("https://www.netfonds.no/quotes/paperhistory.php?paper=API.A&csv_format=csv")
data = quote_date,paper,exch,open,high,low,close,volume,value
20150508,API,Amex,0.39,0.40,0.39,0.40,85933,34194
20150507,API,Amex,0.40,0.41,0.38,0.39,163325,64062
...
like image 40
carandraug Avatar answered Feb 12 '23 10:02

carandraug