toddrob99 / MLB-StatsAPI

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

HTTP Error with get() method becasue it's requiring unneccessary "season" parameter #63

Closed joerex1418 closed 2 years ago

joerex1418 commented 2 years ago

The following is a valid url for the api: http://statsapi.mlb.com/api/v1/teams/145/stats?stats=yearByYear&group=hitting

But if I try running the python wrapper equivalent - mlb.get("team_stats",{"teamId":145,"stats":"yearByYear","group":hitting})

I receive the following error - ValueError: Missing required parameter(s): season.

I reckon that the "season" parameter is only required when retrieving a statType that doesn't need a specific season given. The statTypes - "yearByYear" and "yearByYearAdvanced" are at least two of them that don't require this parameter. There might be more but I have not looked yet.

toddrob99 commented 2 years ago

I will not be able to look into this in detail for a couple weeks, but I suspect you are right. With a couple of statTypes, season isn't required. With the way the endpoint configuration works, there's no way for the code to know when it should be required or not. Let me think about this some more, but in the meantime you can include statsapi.get()'s force=True parameter to bypass the required field check.