rozzac90 / pinnacle

Python Wrapper for Pinnacle Sports API
MIT License
52 stars 26 forks source link

JSONDecodeError when Pinnacle returns a error page instead of data #7

Closed deqing closed 5 years ago

deqing commented 6 years ago
>>> from pinnacle.apiclient import APIClient
>>> api = APIClient(name, passwd)
>>> api.reference_data.get_leagues(29)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pinnacle/endpoints/referencedata.py", line 63, in get_leagues
    response.json().get('leagues', []), resources.LeagueDetails, date_time_sent, datetime.datetime.utcnow()
  File "/usr/local/lib/python3.5/dist-packages/requests/models.py", line 866, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  1 from pinnacle.apiclient import APIClient
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 2)

I guess this might related to encoding, but not sure how to fix it yet.

deqing commented 6 years ago

Ok, I found that it's because Pinnacle API is not allowed to be called from the U.S. so it returns a html saying this information, which will fail the JSON parser.

I guess we need some error handling here.