zero-sum-seattle / python-mlb-statsapi

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

Error Occurred When Using 'get_stats' Method with 'MlbResult' Object in python-mlb-statsapi #201

Closed DnCdad closed 1 year ago

DnCdad commented 1 year ago

I am trying to retrieve MLB-related data using the MLBStatsAPI. When I execute the following code, I encounter an error:

import mlbstatsapi mlb = mlbstatsapi.Mlb()

y = 2022 stats_type = 'season' group_type = 'hitting' params = {'season':y, 'team':142}

year_stats = mlb.get_stats(stats=stats_type, groups=group_type) print(year_stats)

error:

Traceback (most recent call last): File "D:\pythonProject\get_stats__team.py", line 10, in year_stats = mlb.get_stats(stats=stats_type, groups=group_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\GS\AppData\Local\Programs\Python\Python311\Lib\site-packages\mlbstatsapi\mlb_api.py", line 2258, in get_stats splits = mlb_module.create_split_data(mlb_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\GS\AppData\Local\Programs\Python\Python311\Lib\site-packages\mlbstatsapi\mlb_module.py", line 110, in create_split_data for stat in stat_data: TypeError: 'MlbResult' object is not iterable

Mattsface commented 1 year ago

What happens when you pass the params to get_stats?

year_stats = mlb.get_stats(stats=stats_type, groups=group_type, params)

Mattsface commented 1 year ago

or I would just use mlb.get_team_stats

Mattsface commented 1 year ago

I'm going to resolve this. Feel free to open a new issue if you are still having problems.