How to configure the curl package in R with default web proxy settings? How to configure the curl package in R with default web proxy settings? curl curl

How to configure the curl package in R with default web proxy settings?


I was having similar issues. Here are the steps that worked for me:

  1. Download my company's proxy auto-config file (PAC file). For IE: click the gear icon --> internet options --> Connections --> LAN Settings --> copy the http address into a new browser window to download the text file.
  2. Locate the line in the PAC file specifying the proxy (eg: "auth-proxy.xxxxxxx.com:9999")
  3. In a new R session, test these proxy settings by temporarily setting them with a command similar to the following, substituting your values from your PAC file:

    Sys.setenv(http_proxy = "auth-proxy.xxxxxxx.com:9999")Sys.setenv(https_proxy = "auth-proxy.xxxxxxx.com:9999")
  4. Rerun your code in the same session to see if these new settings solve the issue. This is the test I used.

    read_html(curl('http://google.com', handle = curl::new_handle("useragent" = "Mozilla/5.0")))

Setting the proxy using Sys.setenv will only persist to the end of your current session. To make a more permanent change you may consider adding this to your R_PROFILE as explained here.


This is not a beauty, actually it is quite the opposite. But still this hack made it work for me:

library(curl)new_handle_plain = curl::new_handlenew_handle_ntlm = function(){  handle = new_handle_plain()  handle_setopt(handle, .list = list(PROXYUSERPWD = ":"))  return(handle)}rlang::env_unlock(env = asNamespace('curl'))rlang::env_binding_unlock(env = asNamespace('curl'))assign('new_handle', new_handle_ntlm, envir = asNamespace('curl'))rlang::env_binding_lock(env = asNamespace('curl'))rlang::env_lock(asNamespace('curl'))Sys.setenv("http_proxy" = curl::ie_get_proxy_for_url("http://orf.at"))Sys.setenv("https_proxy" = curl::ie_get_proxy_for_url("http://orf.at"))curl_download("http://orf.at", "test.html")

I would still love to see a clean solution as changing an inner function of a library is not something one should do...