Euxitheos
Euxitheos

Reputation: 325

API/JSON Value Error

I've been trying to use an API with the following response when I type in the url:

{
    "resource": "playerdashptshotlog",
    "parameters": {
        "LeagueID": "00",
        "Season": "2014-15",
        "SeasonType": "Regular Season",
        "PlayerID": 202066,
        "TeamID": 0,
        "Outcome": null,
        "Location": null,
        "Month": 0,
        "SeasonSegment": null,
        "DateFrom": null,
        "DateTo": null,
        "OpponentTeamID": 0,
        "VsConference": null,
        "VsDivision": null,
        "GameSegment": null,
        "Period": 0,
        "LastNGames": 0
    },
    "resultSets": [

My code is as follows:

import json, requests
github_url = 'http:dsds
parsed_input = json.loads(github_url)
print (parameters.keys())
print (parameters['LeagueID']['Season'])

I get an error when I use Python34 saying:

Traceback (most recent call last): File "C:\Python34\Scripts\NBA API-JSON.py", line 27, in parsed_input = json.loads(github_url) File "C:\Python34\lib\json__init__.py", line 318, in loads return _default_decoder.decode(s) File "C:\Python34\lib\json\decoder.py", line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode raise ValueError(errmsg("Expecting value", s, err.value)) from None ValueError: Expecting value: line 1 column 1 (char 0)

When I run it on Python27 I get this error:

Traceback (most recent call last): File "C:\Python27\Scripts\NBA API-JSON.py", line 27, in parsed_input = json.loads(github_url) File "C:\Python27\lib\json__init__.py", line 338, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

I'm trying to figure out what I'm doing wrong. I tried using an example answer I found to a question found at:

Parsing Multidimensional JSON Array

Upvotes: 1

Views: 809

Answers (1)

mr nick
mr nick

Reputation: 560

It looks like you forgot to fetch the data. Try:

github_url = 'http://whatever'
r = requests.get(github_url)
if r.status_code == 200:
    parsed_input = json.loads(r.text)

Requests can also parse the JSON for you:

parsed_input = r.json()

Upvotes: 2

Related Questions