pybaseball icon indicating copy to clipboard operation
pybaseball copied to clipboard

Issue: schedule_and_record Fails for Valid Team/Year Combinations

Open elliot-wolf opened this issue 9 months ago • 8 comments

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?

elliot-wolf avatar Mar 11 '25 18:03 elliot-wolf

I'm having the same issue this week even after updating http to https. Other functions seem to work.

bhemp avatar Mar 11 '25 22:03 bhemp

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?

elliot-wolf avatar Mar 12 '25 21:03 elliot-wolf

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.

MancusoM avatar Mar 15 '25 17:03 MancusoM

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

jburgessd avatar Mar 19 '25 14:03 jburgessd

Thanks @jburgessd! Much appreciated

MancusoM avatar Mar 20 '25 01:03 MancusoM

Fix worked for me @jburgessd. Thanks!

bhemp avatar Mar 24 '25 18:03 bhemp

Same issue for me. Looking forward to the PR getting approved since I prefer to wait for the release. Thanks, @jburgessd !

mdstepha avatar Mar 29 '25 18:03 mdstepha

thanks @jburgessd! this solved my cloudflare issue with bwar

stigscousin avatar Apr 24 '25 23:04 stigscousin