How to get data from API server using httr package

Hello,

I am trying to get data from API web server using httr package. For the API URL, it has API key with username & password. Also, URL has multiple parameters to pass. Below is the code & I get this error. Please through some expert advice to get data from API server.

req <- GET("https://ananomyususer.org/api/run-report?api_key=EWRER&report={"reportType":"multipleparameters"));
Error in curl::curl_fetch_memory(url, handle = handle) :
Unable to communicate securely with peer: requested domain name does not match the server's certificate.

This isn't really a reproducible example. And you probably don't want to be sharing your api username and password anyway. I first notice that ananomyususer.org does not seem to be registered to anyone. Did you mask this? Also your api call doesn't include a username, but you suggest it should have one.

The error message "Unable to communicate securely with peer: requested domain name does not match the server's certificate." matches the issue these folks faced: Unable to communicate securely with peer: requested domain name does not match the server’s certificate on community.letsencrypt.org

@EconomiCurtis Thanks for the reply.

Yes, I did mask the website name in the post. Also, This API has authentication with API Key.
I passed the username as variable & tried as below, still got the same error.

url_ben <- 'https://anonymoususer.org/api'

repost <- GET(url = paste0(url_ben,'users/',username,'/repost'))
Error in curl::curl_fetch_memory(url, handle = handle) :
Unable to communicate securely with peer: requested domain name does not match the server's certificate.

Thanks for pointing me the post, but it's not relevant to this issue.

I think if you google around, you'll find that this is a common error when trying to communicate with a website whose SSL certificate is not set up properly (the discussion @EconomiCurtis linked is among web site admins talking about how to fix the problem from their end). So it seems most likely that this is something that ideally needs to be solved by the administrators of the site you're trying to connect to.

Short of that, I know libcurl (which httr is using) has options that will allow you to choose to ignore SSL problems in some circumstances, and that you can set CURL options from httr. So I guess you could try connecting insecurely, but of course all the usual warnings would apply...

1 Like