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

Using Tweety in a Flask App #244

Open
emirhanyuce opened this issue Feb 26, 2025 · 3 comments
Open

Using Tweety in a Flask App #244

emirhanyuce opened this issue Feb 26, 2025 · 3 comments

Comments

@emirhanyuce
Copy link

Hey everyone,

I have been trying to use Tweety inside a Flask App for a small project, where I want to help my non-programmer friends searching tweets with a simple WebApp. The app works on my local just fine does it's tasks, but when I deployed it I got the following error and cannot sign in to accounts I used the library to search for tweets. I intentionally hid the username and password.

tweety.exceptions.ActionRequired: Enter your phone number or email address. There was unusual login activity on your account. To help keep your account safe, please enter your phone number (start with country code, e.g. +1) or email address to verify it’s you.

2025-02-26 08:05:32 - twitter_scraper - ERROR - Error with account [username, pwd ]: API call failed

Has anybody got any experience using the library in a hosted backend, how can I avoid getting this error?

@mahrtayyab
Copy link
Owner

ActionRequired occurs when the login process requires some additional information to complete the login from Twitter.

It could have multiple solutions

  1. using try except block , send the additional information while logging in.
  2. use cookies or auth_token to login

Can you please post your code snippet for better understanding.

@emirhanyuce
Copy link
Author

Thanks for the fast reply here are the relevant parts on how I sign in

# Create a global TwitterAsync instance
twitter_app = TwitterAsync("session")

....
async def call_api(account, query, max_pages=MAX_PAGES_PER_REQUEST):
    global twitter_app
    ....
    login_result = await twitter_app.sign_in(account[0], account[1])

Hence, I am trying to host this on cloud I do not want to use cookies or auth_token because we need to check them if they are expired or not and refresh it periodically. Is it possible or sufficient to provide the email address of the account hence it is asking for it in the error message, if yes what should be the format to provide it with extra arg?

@mahrtayyab
Copy link
Owner

from tweety import TwitterAsync

app = TwitterAsync("session")
try:
    await app.sign_in(username, password, extra=extra)
except ActionRequired as e:
    action = input(f"Action Required :> {str(e.message)} : ")
    await app.sign_in(username, password, extra=action)

More about to signing here

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

2 participants