Issue: schedule_and_record Fails for Valid Team/Year Combinations
The schedule_and_record function is returning a ValueError when attempting to retrieve data for valid team and year combinations. The error message suggests that the team abbreviation or season may be incorrect, but the input values are valid.
Test code:
from pybaseball import schedule_and_record
df = schedule_and_record(2023, "ATL") # Also fails with other teams/years print(df.head())
Error: ValueError: Data cannot be retrieved for this team/year combo. Please verify that your team abbreviation is accurate and that the team existed during the season you are searching for.
Has anyone else experienced this issue?
I'm having the same issue this week even after updating http to https. Other functions seem to work.
The timing is a bit odd, since it was working fine for me last week. I'm wondering if there were changes in the website's structure before the start of the 2025 season?
I'm also having this issue with py.game_logs. I used this code two weeks with no issue, but now it's not working even though I haven't changed it
It looks like the get_table function is not working for game_logs and schedule_and_record. If anyone can identify this issue and fix it, I'd appreciate it
This is my code:
import pybaseball as pyb
for year in range(2009, 2025):
if year == 2020:
continue
batting_logs = pyb.team_game_logs(year, "NYM", "batting")
This is my error message:
Traceback (most recent call last):
File "/Users/mattmancuso/PycharmProjects/Citi_BABIP/Mets.py", line 18, in <module>
batting_logs = pyb.team_game_logs(year, "NYM", "batting")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/mattmancuso/PycharmProjects/Citi_BABIP/.venv/lib/python3.12/site-packages/pybaseball/cache/cache.py", line 58, in _cached
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/mattmancuso/PycharmProjects/Citi_BABIP/.venv/lib/python3.12/site-packages/pybaseball/team_game_logs.py", line 53, in team_game_logs
data = get_table(season, team, log_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/mattmancuso/PycharmProjects/Citi_BABIP/.venv/lib/python3.12/site-packages/pybaseball/team_game_logs.py", line 19, in get_table
raise RuntimeError("Table with expected id not found on scraped page.")
RuntimeError: Table with expected id not found on scraped page.
baseball reference started using cloudflare to verify against the request library. I fixed this by using the curl_cffi library and impersonating chrome. Hope this helps.
Edit: Opened a PR
Thanks @jburgessd! Much appreciated
Fix worked for me @jburgessd. Thanks!
Same issue for me. Looking forward to the PR getting approved since I prefer to wait for the release. Thanks, @jburgessd !
thanks @jburgessd! this solved my cloudflare issue with bwar