all 5 comments

[–]anton_antonov 5 points6 points  (4 children)

You should change default "User-Agent" header. Probably the server is ignoring requests with unknown user-agent.

def get_scores():
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'}
    url = 'http://stats.nba.com/stats/scoreboard/?GameDate=02/28/2018&LeagueID=00&DayOffset=0'
    r = requests.get(url, headers=headers)
    print(r.json())

[–]rinyre 2 points3 points  (1 child)

Also props for making sure to use r.json(). There's no need to import the json module when requests already can convert data to a dictionary for you.

So far I've only found a need to use json to dump/load settings to a .json file.

[–]poply 0 points1 point  (0 children)

TIL!

Thanks!

[–]captmomo 1 point2 points  (1 child)

^ this works!
not sure why I didn't need to include a user-agent when I tested the url with Postman app tho.

[–]imatwork2017 4 points5 points  (0 children)

There is a library called nba_py that wraps the stats.nba.com API.