toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
533 stars 100 forks source link

Missing Players #84

Closed mayeradelman closed 2 years ago

mayeradelman commented 2 years ago

I notice that once in a while there are players whose lookup fails. For example, today there is a player with an ID of 553988 in the San Francisco Giants lineup, but looking up that ID via statsapi.lookup_player results in an IndexError. (The player it's supposed to be is 'Dixon Machado'.)

toddrob99 commented 2 years ago

I'm not getting an IndexError...

>>> import logging
>>> import statsapi
>>> logger = logging.getLogger('statsapi')
>>> logger.setLevel(logging.DEBUG)
>>> rootLogger = logging.getLogger()
>>> rootLogger.setLevel(logging.DEBUG)
>>> ch = logging.StreamHandler()
>>> formatter = logging.Formatter("%(asctime)s - %(levelname)8s - %(name)s(%(thread)s) - %(message)s")
>>> ch.setFormatter(formatter)
>>> rootLogger.addHandler(ch)
>>> statsapi.lookup_player(553988)
2022-07-31 20:40:01,018 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/{ver}/sports/{sportId}/players
2022-07-31 20:40:01,018 -    DEBUG - statsapi(57240) - Found query param: gameType
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - Found query param: season
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - Found path param: sportId
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - Found query param: fields
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - path_params: {'sportId': '1'}
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - query_params: {'gameType': 'R', 'season': '2022', 'fields': 'people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName'}
2022-07-31 20:40:01,019 -    DEBUG - statsapi(57240) - Replacing {sportId}
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/{ver}/sports/1/players
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - Replacing {ver} with default: v1.
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/v1/sports/1/players
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - Adding query parameter gameType=R
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/v1/sports/1/players?gameType=R
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - Adding query parameter season=2022
2022-07-31 20:40:01,020 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/v1/sports/1/players?gameType=R&season=2022
2022-07-31 20:40:01,022 -    DEBUG - statsapi(57240) - Adding query parameter fields=people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName
2022-07-31 20:40:01,022 -    DEBUG - statsapi(57240) - URL: https://statsapi.mlb.com/api/v1/sports/1/players?gameType=R&season=2022&fields=people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName
2022-07-31 20:40:01,031 -    DEBUG - urllib3.connectionpool(57240) - Starting new HTTPS connection (1): statsapi.mlb.com:443
2022-07-31 20:40:01,467 -    DEBUG - urllib3.connectionpool(57240) - https://statsapi.mlb.com:443 "GET /api/v1/sports/1/players?gameType=R&season=2022&fields=people,id,fullName,firstName,lastName,primaryNumber,currentTeam,id,primaryPosition,code,abbreviation,useName,boxscoreName,nickName,mlbDebutDate,nameFirstLast,firstLastName,lastFirstName,lastInitName,initLastName,fullFMLName,fullLFMName HTTP/1.1" 200 None
[{'id': 553988, 'fullName': 'Dixon Machado', 'firstName': 'Dixon', 'lastName': 'Machado', 'primaryNumber': '49', 'currentTeam': {'id': 137}, 'primaryPosition': {'code': '6', 'abbreviation': 'SS'}, 'useName': 'Dixon', 'boxscoreName': 'Machado, D', 'nickName': 'Mongli', 'mlbDebutDate': '2015-05-25', 'nameFirstLast': 'Dixon Machado', 'firstLastName': 'Dixon Machado', 'lastFirstName': 'Machado, Dixon', 'lastInitName': 'Machado, D', 'initLastName': 'D Machado', 'fullFMLName': 'Dixon Javier Machado', 'fullLFMName': 'Machado, Dixon Javier'}]
>>>
mayeradelman commented 2 years ago

I'm not getting it anymore either. Is it possible that it takes time to update players who were recently called up?

toddrob99 commented 2 years ago

I don't think a player id will change when they move between leagues. The record for Dixon Machado has an MLB Debut Date in 2015. I have no idea why it was throwing an error.

mayeradelman commented 2 years ago

Okay, thanks. I'll try to document the issue more thoroughly if I encounter it again. Thanks so much for this awesome API and the help!