GlobalDataLab / R-data-api

R API for GDL Data Retrieval
https://docs.globaldatalab.org/gdldata/index.html
Other
0 stars 0 forks source link

API not working on WSL 2 and google-cloud VM #2

Open marcoaurelioguerrap opened 8 months ago

marcoaurelioguerrap commented 8 months ago

When making request to the API on WSL 2 or a google-cloud VM with Ubunt I get this error:

> lnic_country <- gdl_request(sess)
Error in `req_perform()`:
! Failed to perform HTTP request.
Caused by error in `curl::curl_fetch_memory()`:
! SSL peer certificate or SSH remote key was not OK: [globaldatalab.org] server certificate verification failed. CAfile: none CRLfile: none

It seems that this is a problem with the website certifications. When I use www.ssllabs.com to get the correct certification bundle (Certification Paths). I manage to access the API. image Working using ca-bundle from ssllabs: image

marcoaurelioguerrap commented 8 months ago

Note: On windows works fine

AaronVanGeffen commented 8 months ago

It looks like you're using Ubuntu or Debian on WSL, is that correct? If so, could you verify the ca-certificates package is installed through apt?

marcoaurelioguerrap commented 8 months ago

Yes, it is. image

AaronVanGeffen commented 8 months ago

It seems curl fails to find the certificate bundle, either way (note: CAfile: none CRLfile: none in the error produced by R).

Could you try setting the following environment variable, such that R has access to it?

CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
marcoaurelioguerrap commented 8 months ago

How do I do this?

I have tried the curl option --cacert but it also failed. OBS.: I'm not using the API request not to show my API key. but the result is the same.

image

marcoaurelioguerrap commented 8 months ago

I forgot to mention, not sure if it is important. but my machine that has the WSL 2 does manage to access the API an the website (via curl or API) image

AaronVanGeffen commented 8 months ago

It is also working fine for me on both macOS and Linux, which leads me to believe it is a problem with the setup in the VM you're using. Regardless, a very similar issue was reported in #1, so I would like to get to the bottom of this.

However, it is 11pm on my end, and very much the weekend. I'll happily get back to the issue on Monday. If you find out the cause in the mean time, please do leave a comment.

marcoaurelioguerrap commented 8 months ago

Oh, OK. Sure, no worries, I'm about to finish here as well. It is not a big problem for me. I could download the data on my Windows machine. I thought you guys might want to know about this.

A friend of mine managed to make this work on her Ubuntu so it is problem something on my machine and on the Google Cloud compute engine, I don't know much about network stuff.

marcoaurelioguerrap commented 8 months ago

This post helped me to run the curl using the ca-bundle https://askubuntu.com/questions/1127574/ubuntu-curl-not-recognizing-positivessl-certificate