cwendt94 / espn-api

ESPN Fantasy API! (Football, Basketball)
MIT License
544 stars 183 forks source link

Getting "json.decoder.JSONDecodeError: Unterminated string" starting after NFL week 6 #498

Open loupalladino opened 8 months ago

loupalladino commented 8 months ago

Sport

Football

Summary

Starting somewhere after NFL week 6 or 7, I get a JSONDecodeError all the time, right after invoking 'League':

>>> from espn_api.football import League
>>> league = League(league_id=696706, year=2023)
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 614395 (char 614394)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/football/league.py", line 24, in __init__
    self.fetch_league()
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/football/league.py", line 27, in fetch_league
    self._fetch_league()
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/football/league.py", line 33, in _fetch_league
    self._fetch_players()
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/base_league.py", line 64, in _fetch_players
    data = self.espn_request.get_pro_players()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/requests/espn_requests.py", line 93, in get_pro_players
    data = self.get(extend='/players', params=params, headers=headers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/espn_api/requests/espn_requests.py", line 67, in get
    self.logger.log_request(endpoint=endpoint, params=params, headers=headers, response=r.json())
                                                                                        ^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Unterminated string starting at: line 1 column 614395 (char 614394)

Debug output attached, although the responses seem inconsistent. Sometimes I do get json data back with debug=True before it errors out, but sometimes I don't get any json. Of course, as I go to write this up, no json is coming back. I'll keep trying.

Thoughts? Maybe I've got a dependency mismatch/error somewhere?

Thanks.

Logs/Data

debug1.txt

loupalladino commented 8 months ago

I did get it to return some json data this time - see attached.

debug2.txt

cwendt94 commented 8 months ago

Strange, this seems to be just the request package trying to parse the request response from ESPN API. Im currently using python version 3.8. Maybe try using a older version of python?

loupalladino commented 8 months ago

I installed 3.8.18 from Homebrew and that seems to have resolved the issue. Sorry, I should have thought to try that first. In any event, thanks for the suggestion and thank you for maintaining this package. I use it as part of another program that I run to collect data from our league that we use for prizes/awards at the end of the season.

cwendt94 commented 8 months ago

Nice, I am glad that fixed the issue. Eventually I will upgrade the package to a newer python version and keep a look out for this error!