Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in open.connection(con, "rb") : Timeout was reached: Resolving timed out after 10000 milliseconds

Tags:

r

So I've got a list of "Player" objects, each with an ID, called players and I'm trying to reach a web JSON with information related to the relevant ID, using JSONlite.

The HTML stem is: 'https://fantasy.premierleague.com/drf/element-summary/'

I need to access every players respective page.

I'm trying to do so as follows:

playerDataURLStem = 'https://fantasy.premierleague.com/drf/element-summary/'

for (player in players) {
  player_data_url <- paste(playerDataURLStem,player@id,sep = "")
  player_data <- fromJSON(player_data_url)

  # DO SOME STUFF #

}

When I run it, I'm getting the error Error in open.connection(con, "rb") : Timeout was reached: Resolving timed out after 10000 milliseconds. This error is produced at a different position in my list of players each time I run the code and when I check the webpage that is causing the error, I can't see anything erroneous about it. This leads me to believe that sometimes the pages just take longer than 10000 milliseconds to reply, but using

options(timeout = x)

for some x, doesn't seem to make it wait longer for a response.

For a minimum working example, try:

playerDataURLStem = 'https://fantasy.premierleague.com/drf/element-summary/'

ids <- c(1:540)
for (id in ids) {
    player_data_url <- paste(playerDataURLStem, id, sep = "")
    player_data <- fromJSON(player_data_url)
    print(player_data$history$id[1])
}
like image 877
statskyy Avatar asked Oct 30 '22 01:10

statskyy


1 Answers

options(timeout= 4000000) is working for me .try increasing value of timeout to higher number

like image 117
yash shah Avatar answered Nov 15 '22 05:11

yash shah