Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loupalladino opened this issue Oct 31, 2023 · 4 comments

Comments

@loupalladino
Copy link

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/[email protected]/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/[email protected]/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/[email protected]/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
Copy link
Author

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

debug2.txt

@cwendt94
Copy link
Owner

cwendt94 commented Nov 1, 2023

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
Copy link
Author

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
Copy link
Owner

cwendt94 commented Nov 1, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants