myotis
myotis

Reputation: 423

Octave urlread will not download data due to "Pee

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

Upvotes: 4

Views: 3607

Answers (3)

cynod
cynod

Reputation: 1309

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

Upvotes: 7

eee_user
eee_user

Reputation: 1

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

Upvotes: 0

carandraug
carandraug

Reputation: 13091

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
...

Upvotes: 1

Related Questions