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

Login fails #127

Open
spiros26 opened this issue Jul 30, 2023 · 12 comments
Open

Login fails #127

spiros26 opened this issue Jul 30, 2023 · 12 comments

Comments

@spiros26
Copy link

I can't get the login function to work. Maybe fpl has changed something and the headers don't work?

@ivarbratberg
Copy link

Same here, it says
state = response.url.query["state"]
keyerror

@ivarbratberg
Copy link

/site-packages/fpl/fpl.py) in login(self, email, password)
589 ssl=ssl_context,
590 headers={"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1; PRO 5 Build/LMY47D)"}) as response:
--> 591 state = response.url.query["state"]
592 if state == "fail":

@Tonio101
Copy link
Contributor

Same, seems like its an auth issue. API requires a Cookie now.

@Tonio101
Copy link
Contributor

@spiros26 @ivarbratberg,
Its an auth issue, I am still not sure how to retrieve the pl_profile and datadome, will look through their API to see if theres a way. As a workaround you have to manually edit the code, provide the Cookie and recompile.
It seems like its a one-time thing, I have not had to refresh or get a new version of pl_profile and datadome.

  1. Obtain the pl_profile and datadome from the Session cookie, once you've logged into your PL account.
    You can access the cookies if you log on in chrome and then right click and select inspect > Application > Cookies

Use the code snippet in fpl.py file.

        custom_cookie = {
            'pl_profile': "",
            'datadome': ""
        }

        headers = {
            "User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1; PRO 5 Build/LMY47D)"
        }

        async with self.session.post(login_url, data=payload,
                                     ssl=ssl_context,
                                     cookies=custom_cookie,
                                     headers=headers) as response:
            if 'state' not in response.url.query:
                raise ValueError(f"Unsuccessful login: {response.status_code}")

            state = response.url.query["state"]
            if state == "fail":
                reason = response.url.query["reason"]
                raise ValueError(f"Login not successful, reason: {reason}")

@amosbastian
Copy link
Owner

I released a new version a few days ago that included #126

This PR includes the ability to grab a cookie from the FPL_COOKIE environment variables and add it to the headers if specified

So maybe you can try that out?

@kernalkue
Copy link

I'm having a very hard time figuring out how to put a cookie into an environment variable. Do I format it as json?

@ivarbratberg
Copy link

ivarbratberg commented Aug 18, 2023 via email

@ThatPalAl
Copy link

Any hope for a solution here?
I am unable to login using the pl_profile and data dome, seems like it's still unresolved, right?

@Divinebosst
Copy link

The only solution is to use a selenium bot to login, but it's not effective because the fpl webapp uses datadome for bot detection.

@Tonio101
Copy link
Contributor

Tonio101 commented Oct 22, 2023

Any hope for a solution here? I am unable to login using the pl_profile and data dome, seems like it's still unresolved, right?

@ThatPalAl
Should work, please pass in the correct format for the cookie:

import asyncio
import aiohttp
from fpl import FPL

async def main():
    async with aiohttp.ClientSession() as session:
        fpl = FPL(session)
        await fpl.login(
            email="",
            password="",
            cookie = """datadome=;pl_profile="""
        )
        user = await fpl.get_user()
    print(user)


asyncio.run(main())

@ThatPalAl
Copy link

@Tonio101
Not sure how to interpret that, so I need to replace just the 'datadome' with the value from my current session and same for the 'pl_profile'? I've put String values instead of those keywords but it's still the same 403 response.
Should it look like this:
cookie = """STRING_VALUE_OF_DATADTOME=;STRING_VALUE_OF_PL_PROFILE="""
or is that wrong?

@mustardpower
Copy link

You need to add the values of the cookies after the equals character. So would be:

cookie = """datadome=STRING_VALUE_OF_DATADTOME;pl_profile=STRING_VALUE_OF_PL_PROFILE"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants