Skip to content

Commit

Permalink
[FotMob] patch for new anti-scraping header (#745)
Browse files Browse the repository at this point in the history
FotMob now requires a "x-fm-req" value to be present in the header.

Fixes #742
  • Loading branch information
probberechts authored Nov 4, 2024
1 parent e48a2f9 commit b999c5e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions soccerdata/fotmob.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Callable, Optional, Union

import pandas as pd
import requests

from ._common import BaseRequestsReader, make_game_id
from ._config import DATA_DIR, NOCACHE, NOSTORE, TEAMNAME_REPLACEMENTS, logger
Expand Down Expand Up @@ -78,6 +79,17 @@ def __init__(
(self.data_dir / "seasons").mkdir(parents=True, exist_ok=True)
(self.data_dir / "matches").mkdir(parents=True, exist_ok=True)

def _init_session(self) -> requests.Session:
session = super()._init_session()
try:
r = requests.get("http://46.101.91.154:6006/")
r.raise_for_status()
except requests.exceptions.ConnectionError:
raise ConnectionError("Unable to connect to the session cookie server.")
result = r.json()
session.headers.update(result)
return session

@property
def leagues(self) -> list[str]:
"""Return a list of selected leagues."""
Expand Down

0 comments on commit b999c5e

Please sign in to comment.