Skip to content Skip to sidebar Skip to footer

Error In Open.connection(x, "rb") : Couldn't Connect To Server

I receive the following error when attempting to use the rvest package in R: Error in open.connection(x, 'rb') : Couldn't connect to server What is causing this error message? T

Solution 1:

I tried different ways and the problem was not in the proxy connection, but in the way that R gets the connection. Through the definition of a binary connection of the url within url() the problem was solved.

con <- url("http://www.imdb.com/title/tt1490017/", "rb") 
lego_movie <- read_html(con)

Solution 2:

You have to open a session and then read from it

htmlpage <- html_session("http://forecast.weather.gov/MapClick.php?lat=42.27925753000045&lon=-71.41616624299962#.V17UH-IrKHs", httr::user_agent("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.20 (KHTML, like Gecko) Chrome/11.0.672.2 Safari/534.20"))

htmlpage %>%
  read_html() %>%
  html_text()

Solution 3:

The problem is that your work computer is always looking for your company's proxy server, and this happens whether or not you are at work, or using a hotspot, or even at home.

The easiest way to overcome this is to add a parameter atWork to your function and then use the httr::use_proxy() function to set the appropriate proxy to use:

myFunction <- function(arg1, atWork)

    if(atWork){
        proxy.string <- use_proxy("http://proxy-server.YourCompanyName.com", port = 8080)
    } else {
        proxy.string <- use_proxy("")
    }

# then open a session
sess <- html_session(myUrl, proxy.string)

do stuff here
return(result)
}

of course, you will need to replace proxy-server.YourCompanyName with your actual company's proxy server url.

Post a Comment for "Error In Open.connection(x, "rb") : Couldn't Connect To Server"