Avyay Varadarajan
Avyay Varadarajan

Reputation: 45

Open Uri not opening url even though browser opens it

I am trying to open a url with open-uri and when I open it from my browser, Safari, it takes me to the page in a second. However, when I try to open it with open-uri, it doesn't work. It says Net::ReadTimeout: Net::ReadTimeout, after a minute. It takes one second to open the url with my browser, but it doesn't work with open-uri ever. I have tried to increase the max timeout time but it doesn't work.

open(url).read

This is the code I use to open the url, and it doesn't work when I do it in the code.

Upvotes: 1

Views: 700

Answers (1)

Josh Brody
Josh Brody

Reputation: 5363

Looks like they're protecting their API against really vague requests.

`curl 'http://stats.nba.com/stats/commonallplayers?LeagueID=00&Season=2016-17&IsOnlyCurrentSeason=1' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,ru;q=0.6' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'` 

will do it just fine.

Upvotes: 2

Related Questions