swar / nba_api

An API Client package to access the APIs for NBA.com
MIT License
2.54k stars 542 forks source link

Fix BoxScoreTraditionalV3 API Bug(some game stats starters and bench is None, cause 'NoneType' object has no attribute 'values') #458

Closed XatMassacrE closed 3 months ago

XatMassacrE commented 3 months ago

For example: endpoint is : boxscoretraditionalv3 Game 0012300001, period 4, params is:

  params = {
    'game_id': '0012300001',
    'range_type': 1,
    'start_period': 4,
    'end_period': 4,
  }

NBA official Website response is like this(starters and bench is null): image

but nba_api will throw an error:

  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/endpoints/boxscoretraditionalv3.py", line 141, in __init__
    self.get_request()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/endpoints/boxscoretraditionalv3.py", line 151, in get_request
    self.load_response()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/endpoints/boxscoretraditionalv3.py", line 154, in load_response
    data_sets = self.nba_response.get_data_sets(self.endpoint)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/library/http.py", line 150, in get_data_sets
    return endpoint_parser.get_data_sets()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/library/parserv3.py", line 234, in get_data_sets
    start_bench_data = self.get_start_bench_data()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/nba_api/stats/library/parserv3.py", line 145, in get_start_bench_data
    x for x in raw_dict["homeTeam"]["starters"].values()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'values'