zero-sum-seattle / python-mlb-statsapi

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

`get_schedule` throws an error (bug) #209

Closed Daniel-Packer closed 1 month ago

Daniel-Packer commented 1 month ago

Hi folks,

I'm not quite sure what the correct way for me to report a bug, so I'm gonna put it here. I also don't know if I have a bug or a stale version. I installed mlbstatsapi via pip this afternoon (May 24, 2024).

I was attempting to pull today's schedule with

import mlbstatsapi

mlb = mlbstatsapi.Mlb()
schedule = mlb.get_schedule("2022-10-13")

But this throws an error that looks like:

Traceback (most recent call last):
  File "/home/daniel/Documents/betting/src/get_game_outcomes.py", line 9, in <module>
    schedule = mlb.get_schedule("2022-10-13")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/mambaforge-pypy3/envs/pystats/lib/python3.11/site-packages/mlbstatsapi/mlb_api.py", line 775, in get_schedule
    return Schedule(**mlb_data.data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 8, in __init__
  File "/home/daniel/mambaforge-pypy3/envs/pystats/lib/python3.11/site-packages/mlbstatsapi/models/schedules/schedule.py", line 34, in __post_init__
    self.dates = [ScheduleDates(**date) for date in self.dates if self.dates]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/mambaforge-pypy3/envs/pystats/lib/python3.11/site-packages/mlbstatsapi/models/schedules/schedule.py", line 34, in <listcomp>
    self.dates = [ScheduleDates(**date) for date in self.dates if self.dates]
                  ^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 10, in __init__
  File "/home/daniel/mambaforge-pypy3/envs/pystats/lib/python3.11/site-packages/mlbstatsapi/models/schedules/attributes.py", line 215, in __post_init__
    self.games = [ScheduleGames(**game) for game in self.games ] if self.games else self.games
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/mambaforge-pypy3/envs/pystats/lib/python3.11/site-packages/mlbstatsapi/models/schedules/attributes.py", line 215, in <listcomp>
    self.games = [ScheduleGames(**game) for game in self.games ] if self.games else self.games
                  ^^^^^^^^^^^^^^^^^^^^^
TypeError: ScheduleGames.__init__() got an unexpected keyword argument 'gameguid'

(please excuse me not censoring my local path).

Anyways, y'all can read an error as well as I can.

Is this a real error in the library? I'm happy to try to fix it and make a PR if so!

Thanks a ton, Dan

KCNilssen commented 1 month ago

Hey Dan! Thanks for the Issue! Im curious as to which version you have installed. Locally, trying to recreate your issue I don't fall in to any issue. Try using pip show mlbstatsapi and let me know which version you are dealing with!

The error you are coming across is what happens when you are dealing with an updated version of the mlb api when our library hasn't been updated yet to accommodate those updates.

Daniel-Packer commented 1 month ago

I'm using conda for environment management. Let me know if that changes anything! Anyway, conda list gives: mlb-statsapi 1.6.1 pypi_0 pypi I theoretically still installed it from pip, so I'm not sure what's wrong! Thanks!

KCNilssen commented 1 month ago

Daniel-Packer, Apologies for such a long wait. Some things came up IRL but everything should be groovy now. Update and give it a try. If you have issues still after updating plz open another issue