Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FPL session data #128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions fpl/fpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
Expand Down