4

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

myotis
  • 393
  • 4
  • 16

3 Answers3

7

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

cynod
  • 1,209
  • 1
  • 10
  • 10
  • The course I'm assuming he is talking about (because it worked for me) is "Machine Learning" and is offered at Coursera. The file that contains the above line of code for the week 2 homework assignment is ".../ex1/lib/submitWithConfiguration.m". Open that file then ctrl+f 'urlread' and replace that line with the one in this answer. – Brennen Sprimont Jan 08 '17 at 00:24
  • It seems this is relevant with Coursera Machine Leaning assignment submission only? – mon Jan 17 '17 at 00:26
1

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
...
carandraug
  • 12,938
  • 1
  • 26
  • 38
  • Thanks for your thorough answer.! Where can I find my web browsers list of trusted certificates, and if the one you mention, "GlobalSign_Root_CA_-_R2.pem" is not there, how do I install it, and from where? – myotis Jun 06 '15 at 14:35
  • @EspenDonali that will be very dependent on your OS, the browser, and any extra configuration you may have (such as language settings). I cannot help you with that. – carandraug Jun 06 '15 at 16:33
  • At least I found a way around, even though it does not solve the problem. By changing the `https:` part of the adress into `http:` I was able to download the data. – myotis Jun 06 '15 at 18:23
0

For Windows a workaround is to use the curl command in the Windows console. This can be called by Octave via the system command. With the curl command you can chose the option '--insecure' that will also allow connection to websites without certificates. Only use this option if you're sure the website is safe.

sURLLink = 'https://www.netfonds.no/quotes/paperhistory.php?paper=API.A&csv_format=csv'
command=['curl --insecure ','"',sURLLink,'"']; 
[status, output] =system(command);