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

Question: How to use mfa_code #203

Open
takabinance opened this issue Jun 28, 2024 · 5 comments
Open

Question: How to use mfa_code #203

takabinance opened this issue Jun 28, 2024 · 5 comments
Labels

Comments

@takabinance
Copy link

takabinance commented Jun 28, 2024

I can see there is some support to handle the main problem people seem to be having with banned accounts with login.login_two_factor_auth_challenge(). But not sure how it's connected in or how I can force its invocation. This code is way above my pay grade.

I was able to manually recover an account and updated cookies in accounts.db and then twscrape used it fine.

Does anyone know a way to invoke this and update accounts? I can probably hack together some Selenium thing but would rather not.

@vladkens
Copy link
Owner

Hi, @takabinance.

MFA code is used at login time only.

When you add accounts, you can specify the account's MFA code and then, if X asks for that login stap, twscrape will try to enter that code. But this process only works during login.

There are several methods in twscarpe to deal with inactive accounts:

    relogin                   Re-login selected accounts
    relogin_failed            Retry login for failed accounts

So you use it like (in command line). Try to relogin all failed accounts:

twscrape relogin_failed

Relogin specific accounts:

twscrape relogin acc1 acc2

Or use from code:

import asyncio

from twscrape import API, gather
from twscrape.models import parse_tweets

async def main():
    api = API()
    await api.pool.relogin(["acc1", "acc2"])
    await api.pool.relogin_failed()

if __name__ == "__main__":
    asyncio.run(main())

@vladkens vladkens changed the title How to use mfa_code Question: How to use mfa_code Jun 29, 2024
@takabinance
Copy link
Author

Interesting. I will try this. I did it in selenium and then manually updated cookies in accounts.db and was able to use the account again. But will try the built-in functionality.

@takabinance
Copy link
Author

I did the following:

api.pool.add_account(username, password, email, email_password, cookies, mfa_code)
await gather(api.search("elon musk", limit=20))

This worked. However, when I tried to force a login:

api.pool.relogin(['mytwitteruser'])

I got:

Failed to login 'AllgoodMar15077': 400 - {"errors":[{"code":399,"message":"Incorrect. Please try again."}]}

How can I interpret this?

@takabinance
Copy link
Author

ok, so I manually went through the login (username -> email -> password -> 2fa). When I did that manually, it threw up a generic "something went wrong" modal and did not log me back in. However, I was on a VPN connection. I turned off the VPN connection and then it worked manually and also app.pool.relogin() worked as well.

@frameartist
Copy link

From the source code I read the mfa_code isn't the 6 digit number you type when you try to login. It's the 'secret' for generating the six digit code when you first setup 2fa, so if you are setting the 6 digits as the mfa_code, it probably won't work.

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

No branches or pull requests

3 participants