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

Issue: Unable to Login to X.com API Using twikit Client - LoginFlow Not Accessible (Error 400) #227

Open
aqbspl opened this issue Oct 4, 2024 · 18 comments

Comments

@aqbspl
Copy link

aqbspl commented Oct 4, 2024

I am trying to authenticate to X.com (formerly Twitter) using the twikit Python client. While attempting to log in using my credentials or cookies, I consistently encounter the following error:
status: 400, message: "{"errors":[{"code":366,"message":"flow name LoginFlow is currently not accessible"}]}"
Steps to Reproduce
Load or attempt to log in with credentials or cookies.
Run the script using twikit's Client.login() function.
Example Code Snippet

from twikit import Client
import asyncio
from configparser import ConfigParser

# Load credentials
config = ConfigParser()
config.read('config.ini')
username = config['X']['username']
email = config['X']['email']
password = config['X']['password']

client = Client(language='en-US')

async def main():
    try:
        await client.login(auth_info_1=username, auth_info_2=email, password=password)
        client.save_cookies('cookies.json')
        print("Login successful, cookies saved.")
    except Exception as e:
        print(f"Login failed: {e}")

# Run the async function
asyncio.run(main())

Error Message
status: 400, message: "{"errors":[{"code":366,"message":"flow name LoginFlow is currently not accessible"}]}"
Additional Information

  • Environment: Ubuntu 22 LTS, Python 3.10

  • Library version: twikit vX.X.X (latest version)

  • X.com API Access: Standard user account (no developer API access)
    Tried solutions:

  • Using valid credentials

Expected Behavior
Successful login and subsequent authentication using either credentials or cookies.

Actual Behavior
The login process fails with a 400 error, and the LoginFlow is reported as "not accessible".

Request for Help

  • Is this a known issue related to changes in X.com's authentication flow?
  • Any workarounds or solutions for this issue would be greatly appreciated.
@PhatStraw
Copy link

PhatStraw commented Oct 5, 2024

if os.path.exists("cookies.json"):
        client.load_cookies("cookies.json")
    else:
        await client.login(
            auth_info_1=AUTH_INFO_1, auth_info_2=AUTH_INFO_2, password=PASSWORD
        )
        client.save_cookies("cookies.json")
    load the cookie

@aqbspl
Copy link
Author

aqbspl commented Oct 5, 2024

if os.path.exists("cookies.json"):
        client.load_cookies("cookies.json")
    else:
        await client.login(
            auth_info_1=AUTH_INFO_1, auth_info_2=AUTH_INFO_2, password=PASSWORD
        )
        client.save_cookies("cookies.json")
    load the cookie

Thanks for the suggestion!

The issue I'm facing occurs during the login process itself. When I try to log in using credentials, I receive the following error:
status: 400, message: "{"errors":[{"code":366,"message":"flow name LoginFlow is currently not accessible"}]}"

Since the login isn't successful, the client.save_cookies() step doesn't execute, so I can't generate or use the cookies.json file. That’s why even if I use a check for the existence of cookies.json, it doesn't resolve the underlying issue.

Do you have any suggestions on how to handle this or bypass the login issue?

@mohanad-hafez
Copy link

mohanad-hafez commented Oct 5, 2024

did you solve the issue? @aqbspl

@aqbspl
Copy link
Author

aqbspl commented Oct 5, 2024

did you solve the issue? @aqbspl

Not yet, @mohanad-hafez I am getting the same error

@jwaitzel
Copy link

jwaitzel commented Oct 5, 2024

Same issue here

@mohanad-hafez
Copy link

was anyone able to solve this? or did you find other alternatives?

@zecarreira
Copy link

I'm trying it today, and I have the same issue.. any idea?

@Strookyy
Copy link

use this repo:
https://github.com/mdmrcglu/twikit

worked for me, just install with:
pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git

theres a pull request to merge this into the main branch

@dvilelaf
Copy link

use this repo: https://github.com/mdmrcglu/twikit

worked for me, just install with: pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git

theres a pull request to merge this into the main branch

This solution produces the following exception for me on utils.py:103:

    return self.response['subtasks'][0]['subtask_id']
IndexError: list index out of range

@IK-O
Copy link

IK-O commented Oct 16, 2024

I installed with: pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git

but same error occurs.

return self.response['subtasks'][0]['subtask_id']
IndexError: list index out of range

@szsyzx
Copy link

szsyzx commented Oct 21, 2024

Is there no solution to this problem?

@eatpwsyy
Copy link

eatpwsyy commented Oct 22, 2024

use this repo: https://github.com/mdmrcglu/twikit

worked for me, just install with: pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git

theres a pull request to merge this into the main branch

I use this and i got no error
status: 400, message: "{"errors":[{"code":366,"message":"flow name LoginFlow is currently not accessible"}]}

but I got wrong password. I Have confidence my password is correct.

An error occurred during login: status: 400, message: "{"errors":[{"code":399,"message":"Wrong password!"}]}"

I try to catch the error :

except Exception as e:
        print(f"An error occurred during login: {e}")
        print(f"Email: {email}")
        print(f"Username: {username}")
        print(f"Password: {password}")

the result is same as the config.ini file i used but it said wrong password

@desktop69
Copy link

use this repo: https://github.com/mdmrcglu/twikit
worked for me, just install with: pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git
theres a pull request to merge this into the main branch

This solution produces the following exception for me on utils.py:103:

    return self.response['subtasks'][0]['subtask_id']
IndexError: list index out of range

hey @dvilelaf did you solve that problem ?

@theordev
Copy link

theordev commented Nov 7, 2024

use this repo: https://github.com/mdmrcglu/twikit
worked for me, just install with: pip3 install --upgrade git+https://github.com/mdmrcglu/twikit.git
theres a pull request to merge this into the main branch

This solution produces the following exception for me on utils.py:103:

    return self.response['subtasks'][0]['subtask_id']
IndexError: list index out of range

hey @dvilelaf did you solve that problem ?

same here, anyone resolved it ?

@dvilelaf
Copy link

dvilelaf commented Nov 7, 2024

Not really, both repos show issues for me, but not always. Sometimes it just works. For now, i'm logging via cookies. Looking forward for the fix PRs to be merged.

@brownepres
Copy link

How do you log via cookies? Is there a tutorial somewhere which I missed? @dvilelaf

@dvilelaf
Copy link

dvilelaf commented Nov 8, 2024

How do you log via cookies? Is there a tutorial somewhere which I missed? @dvilelaf

#227 (comment)

You will need to extract the cookies from your browser

@brownepres
Copy link

Oh, okay. Haven't thought about that solution yet. Thanks!

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