1

In python I use requests to call an API (cannot share the API itself unfortunately so this is hard to reproduce) in the following way:

import requests
url = url
headers = {'API-key': 'xxxxxxxxxxxxxxxx',
       'Content-type': 'application/json',
       'Accept': 'application/json'
       }

r = requests.get(url, headers = headers, verify=False)
print(r.text)

Here, I think the verify=False forces request to ignore the SSL certificate (as suggested here). This works fine, however I am not able to reproduce it with httr the following way:

 library(httr)

url <- url
headers <- c('API-key' = 'xxxxxxxxxxxxxxxx',
             'Content-type' = 'application/json',
              'Accept' = 'application/json'
          ))

GET(url = url, add_headers(headers = headers)

Now, I believe that verify=False in the requests code is the key here, someone suggested that the way to ignore SSL certificates with httr is using set_config() before a request:

httr::set_config(httr::config(ssl_verifypeer=0L, ssl_verifyhost=0L))

GET(url = url, add_headers(headers = headers))

But it is not working.

$message
[1] "Unauthorized"

$http_status_code
[1] 401

Is httr::set_config(httr::config(ssl_verifypeer=0L, ssl_verifyhost=0L)) the equivalent to verify=False in a requests call?

FilipW
  • 1,412
  • 1
  • 13
  • 25
  • What exactly are the errors you are getting? What type of "unauthorized" are you getting? Is it an actual response from the server or is it an SSL certificate issue? If you are asking for R help, you should describe exactly what `verify=False` does in the python request so we can tell you how to do the same with `httr`. – MrFlick May 20 '19 at 15:20
  • Sure, I have added the error message and tried to explain what `verify=False` does in `requests`. In the documentation it says: Requests can also ignore verifying the SSL certificate if you set verify to False. – FilipW May 21 '19 at 06:55

1 Answers1

2

The error message you showed is really a response from the server. Is has nothing to do with the SSL certificate so you don’t need to disable that checking at all.

The problem is that the name of the parameter in add_headers is .headers not headers. You just need to do

GET(url = url, add_headers(.headers = headers)
MrFlick
  • 195,160
  • 17
  • 277
  • 295