From 77933a914bc4a06e355c05ee2a6cadb7001d35bf Mon Sep 17 00:00:00 2001 From: Antonio Date: Sun, 8 Oct 2023 10:18:08 -0700 Subject: [PATCH 1/2] Add FPL session data --- fpl/fpl.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fpl/fpl.py b/fpl/fpl.py index e9352f4..8167c4d 100644 --- a/fpl/fpl.py +++ b/fpl/fpl.py @@ -578,6 +578,8 @@ async def login(self, email=None, password=None, cookie=None): password = os.getenv("FPL_PASSWORD", None) if not email or not password: raise ValueError("Email and password must be set") + if not cookie: + raise ValueError("Must provide Cookie FPL session data (pl_profile, datadome)") payload = { "login": email, @@ -586,23 +588,23 @@ async def login(self, email=None, password=None, cookie=None): "redirect_uri": "https://fantasy.premierleague.com/a/login" } - if not cookie: - cookie = os.getenv('FPL_COOKIE') headers = { "User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1; PRO 5 Build/LMY47D)", } - if cookie is not None: - headers['Cookie'] = cookie login_url = "https://users.premierleague.com/accounts/login/" async with self.session.post(login_url, data=payload, ssl=ssl_context, + cookies=cookie, headers=headers) as response: if response.status == 403: raise Exception('403 forbidden returned by FPL API, consider setting FPL_COOKIE environment variable ' 'to the cookie in your browser when logged into the fpl website.') + if 'state' not in response.url.query: + raise Exception(f"Unsuccessful login, states not found: {response.status_code}") + state = response.url.query["state"] if state == "fail": reason = response.url.query["reason"] From 4fb80d9e496c498c17f2f7b840f9d559ee1d51b1 Mon Sep 17 00:00:00 2001 From: Antonio Date: Sun, 8 Oct 2023 10:20:38 -0700 Subject: [PATCH 2/2] Minor comment change --- fpl/fpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpl/fpl.py b/fpl/fpl.py index 8167c4d..db6a4b9 100644 --- a/fpl/fpl.py +++ b/fpl/fpl.py @@ -579,7 +579,7 @@ async def login(self, email=None, password=None, cookie=None): if not email or not password: raise ValueError("Email and password must be set") if not cookie: - raise ValueError("Must provide Cookie FPL session data (pl_profile, datadome)") + raise ValueError("Must provide Cookie FPL session data {\"pl_profile\":\"\", \"datadome\":\"\"}") payload = { "login": email,