zero-sum-seattle / python-mlb-statsapi

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

TypeError: PitchBreak.__init__() missing 2 required positional arguments: 'breaklength' and 'breaky' for games in progress #222

Open themarkwilliams opened 2 weeks ago

themarkwilliams commented 2 weeks ago

get_game is returning a type error, "TypeError: PitchBreak.init() missing 2 required positional arguments: 'breaklength' and 'breaky'" for games in progress.

As of 9:28 Central time on 8/26/24: For 745458, which is final, no error is returned.

For 745113, which is in progress, the error is returned.

KCNilssen commented 2 weeks ago

@themarkwilliams I tried to recreate your issue and im not able to:

>>> import mlbstatsapi
>>> mlb = mlbstatsapi.Mlb()
>>> game = mlb.get_game(745113)
>>> 

Let me try this on a current game in progress later (i'm in Europe and game times don't match up to well for me atm). If you can reproduce this with a different game please post your full error message so I can have some more info, thanks!

themarkwilliams commented 2 weeks ago

@themarkwilliams I tried to recreate your issue and im not able to:

>>> import mlbstatsapi
>>> mlb = mlbstatsapi.Mlb()
>>> game = mlb.get_game(745113)
>>> 

Let me try this on a current game in progress later (i'm in Europe and game times don't match up to well for me atm). If you can reproduce this with a different game please post your full error message so I can have some more info, thanks!

Here you go for Game 745132:

Traceback (most recent call last):
  File "C:\Dropbox\Code\game-monitor\game-monitor-baseball.py", line 489, in <module>
    monitor_game(gameid, "baseball")
  File "C:\Dropbox\Code\game-monitor\game-monitor-baseball.py", line 250, in monitor_game
    game_data = mlb.get_game(id)
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\mlb_api.py", line 907, in get_game
    return Game(**mlb_data.data)
  File "<string>", line 8, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\game.py", line 44, in __post_init__
    self.livedata = LiveData(**self.livedata)
  File "<string>", line 8, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\livedata.py", line 37, in __post_init__
    self.plays = Plays(**self.plays)
  File "<string>", line 7, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\plays.py", line 31, in __post_init__
    self.allplays = [Play(**play) for play in self.allplays if play]
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\plays.py", line 31, in <listcomp>
    self.allplays = [Play(**play) for play in self.allplays if play]
  File "<string>", line 15, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\play.py", line 62, in __post_init__
    self.playevents = [PlayEvent(**playevent) for playevent in self.playevents]
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\play.py", line 62, in <listcomp>
    self.playevents = [PlayEvent(**playevent) for playevent in self.playevents]
  File "<string>", line 26, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\playevent\playevent.py", line 77, in __post_init__
    self.pitchdata = PitchData(**self.pitchdata) if self.pitchdata else self.pitchdata
  File "<string>", line 15, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\data\data.py", line 153, in __post_init__
    self.breaks = PitchBreak(**self.breaks) if self.breaks else self.breaks
TypeError: PitchBreak.__init__() missing 2 required positional arguments: 'breaklength' and 'breaky'
KCNilssen commented 2 weeks ago

@themarkwilliams Can you let me know what version you are using? The current library does handle pitch break data with the attributes breaklength and breaky. I'll attach the link to pitchbreak.

https://github.com/zero-sum-seattle/python-mlb-statsapi/blob/e549ba487f4d7a58ab740c6850f2c3bed3c5627a/mlbstatsapi/models/data/data.py#L7-L38

themarkwilliams commented 2 weeks ago

That's certainly part of it! I had run a pip install upgrade on the module, but that only left me a 0.5.23. I am now at 0.5.30 and getting a different error shown below (and same as in #209 and #200)

Traceback (most recent call last):
  File "C:\Dropbox\Code\game-monitor\game-monitor-baseball.py", line 104, in seconds_until_game
    schedule = mlb.get_schedule("2024-08-29")
  File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\mlb_api.py", line 775, in get_schedule     
    return Schedule(**mlb_data.data)
  File "<string>", line 8, in __init__
  File "C:\Dropbox\Code\game-monitor\.venv\lib\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 "C:\Dropbox\Code\game-monitor\.venv\lib\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 "C:\Dropbox\Code\game-monitor\.venv\lib\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 "C:\Dropbox\Code\game-monitor\.venv\lib\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'

Updated the rest of the modules too, but that has not had an impact:


certifi==2024.7.4
charset-normalizer==3.3.2
idna==3.8
lxml==5.3.0
packaging==24.1
python-mlb-statsapi @ https://github.com/zero-sum-seattle/python-mlb-statsapi/archive/refs/tags/v0.5.3.zip#sha256=42644d9d823a320589f2974e87047678cb54a1e54395d87733f7af022b478c71
pytz==2024.1
requests==2.32.3
requests-mock==1.12.1
six==1.16.0
urllib3==2.2.2
``
KCNilssen commented 2 weeks ago

@themarkwilliams it looks like its another issue with pypi. The library is on version 0.5.24. I asked @Mattsface to fix his pypi account to get it working but I haven't heard anything yet about it being fixed. Let me try to get in contact with him again and if we can't get it fixed I might just go ahead and migrate the library to my own account to circumvent this error in the future.

@Mattsface can you get on this soon?

KCNilssen commented 2 weeks ago

In the mean time if you are able to locate your instillation of mlbstatsapi and try to update it manually from this repo that would be a good quick fix for the meantime until we can get this sorted out, sorry for the problems!

themarkwilliams commented 2 weeks ago

Where would I find 0.5.24. I'm only seeing 0.5.30 in the releases section.

KCNilssen commented 2 weeks ago

@themarkwilliams there is no "official release" for this current state right now. If you go to the "main" branch and download it as a zip it should be 0.5.24. That should fix your issues until @Mattsface can get his pypi sorted out.

themarkwilliams commented 2 weeks ago

Got it. Thank you.

Though, I updated to 0.5.24 and am still getting the same break errors:

https://statsapi.mlb.com/api/v1.1/game/745699/feed/live Traceback (most recent call last): File "C:\Dropbox\Code\game-monitor\game-monitor-baseball.py", line 493, in <module> monitor_game(gameid, "baseball") File "C:\Dropbox\Code\game-monitor\game-monitor-baseball.py", line 254, in monitor_game game_data = mlb.get_game(id) File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\mlb_api.py", line 907, in get_game return Game(**mlb_data.data) File "<string>", line 8, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\game.py", line 44, in __post_init__ self.livedata = LiveData(**self.livedata) File "<string>", line 8, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\livedata.py", line 37, in __post_init__ self.plays = Plays(**self.plays) File "<string>", line 7, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\plays.py", line 31, in __post_init__ self.allplays = [Play(**play) for play in self.allplays if play] File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\plays.py", line 31, in <listcomp> self.allplays = [Play(**play) for play in self.allplays if play] File "<string>", line 15, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\play.py", line 62, in __post_init__ self.playevents = [PlayEvent(**playevent) for playevent in self.playevents] File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\play.py", line 62, in <listcomp> self.playevents = [PlayEvent(**playevent) for playevent in self.playevents] File "<string>", line 26, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\game\livedata\plays\play\playevent\playevent.py", line 77, in __post_init__ self.pitchdata = PitchData(**self.pitchdata) if self.pitchdata else self.pitchdata File "<string>", line 15, in __init__ File "C:\Dropbox\Code\game-monitor\.venv\lib\site-packages\mlbstatsapi\models\data\data.py", line 153, in __post_init__ self.breaks = PitchBreak(**self.breaks) if self.breaks else self.breaks TypeError: PitchBreak.__init__() missing 2 required positional arguments: 'breaklength' and 'breaky'

(.venv) PS C:\Dropbox\Code\game-monitor> pip show python-mlb-statsapi Name: python-mlb-statsapi Version: 0.5.24