zero-sum-seattle / python-mlb-statsapi

Python Wrapper for the MLB's Official Stats API
MIT License
48 stars 11 forks source link

TypeError: Player.__init__() missing 1 required keyword-only argument: 'parentteamid' in get_team_roster #216

Closed mgbeck002 closed 5 months ago

mgbeck002 commented 5 months ago

Looks like it's a case sensitivity thing.

See the output from this endpoint: https://statsapi.mlb.com/api/v1/teams/120/roster as an example.

This can be reproduced by using the get_team_roster function with the following arguments: 120, rosterType="active", date="2024-06-24"

KCNilssen commented 5 months ago

@mgbeck002 make sure you are up to date with the most current release, 0.5.22. I tried to reproduce your error and I am not able to.

The following does not produce any sort of error for me

>>> import mlbstatsapi
>>> mlb = mlbstatsapi.Mlb()
>>> print (mlb.get_team_roster(120, rosterType="active", date="2024-06-24"))

The Player data class in 0.5.22 has the attribute parentteamid already implemented

https://github.com/zero-sum-seattle/python-mlb-statsapi/blob/ae6e338bc89ff93196c1be0a872179d841ea3e11/mlbstatsapi/models/people/people.py#L170-L191

Upgrade and let me know if this issue still persists. If it does, post the output please

mgbeck002 commented 5 months ago

Sorry. I assumed it was an issue for all teams. Looks like it's an issue with the Phillies id 143. Specifically this player:

{
person: {
id: 675650,
fullName: "Michael Mercado",
link: "/api/v1/people/675650"
},
jerseyNumber: "63",
position: {
code: "1",
name: "Pitcher",
type: "Pitcher",
abbreviation: "P"
},
status: {
code: "A",
description: "Active"
}
},
import mlbstatsapi
mlb = mlbstatsapi.Mlb()

for team in mlb.get_teams():
    try:
        mlb.get_team_roster(team.id, rosterType="active", date="2024-06-24")
    except TypeError as e:
        print(f"Type error for team: {team.id}")

Type error for team: 143
KCNilssen commented 5 months ago

@mgbeck002 thanks for included that information! It turns out you were right with that one edge case, the player Michael Mercado did not have a parentteamid and since it was a mandatory field it was throwing the error. Changed this to an optional field due the the situation and now everything should work. Upgrade to 0.5.23 and this should be fixed for you!

mgbeck002 commented 5 months ago

Thanks. That fixed it