d60 / twikit

Twitter API Scraper | Without an API key | Twitter Internal API | Free | Twitter scraper | Twitter Bot
https://twikit.readthedocs.io/en/latest/twikit.html
MIT License
1.27k stars 144 forks source link

"LoginFlow is currently not accessible" error when trying to set the user_agent to same as my actual browser #208

Open RisenCrypto opened 3 weeks ago

RisenCrypto commented 3 weeks ago

Program

client = Client(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')

async def main():
    # Asynchronous client methods are coroutines and
    # must be called using `await`.
    await client.login(
        auth_info_1=USERNAME,
        auth_info_2=EMAIL,
        password=PASSWORD
    )

    tweets = await client.search_tweet('query', 'Latest')
    for tweet in tweets:
        print(tweet)

asyncio.run(main())

Gives an error

Traceback (most recent call last):
  File "C:\tmp\tw\examples\ex3.py", line 28, in <module>
    asyncio.run(main())
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\tmp\tw\examples\ex3.py", line 17, in main
    await client.login(
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\site-packages\twikit\client\client.py", line 400, in login
    await flow.execute_task({
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\site-packages\twikit\utils.py", line 88, in execute_task
    response, _ = await self._client.v11.onboarding_task(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\site-packages\twikit\client\v11.py", line 85, in onboarding_task
    return await self.base.post(
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\site-packages\twikit\client\client.py", line 190, in post
    return await self.request('POST', url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\userid\AppData\Local\Programs\Python\Python312\Lib\site-packages\twikit\client\client.py", line 164, in request
    raise BadRequest(message, headers=response.headers)
twikit.errors.BadRequest: status: 400, message: "{"errors":[{"code":366,"message":"flow name LoginFlow is currently not accessible"}]}"

If I replace the

client = Client(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')

with

client = Client('en-US')

the program works perfectly.

I am on Windows 11.

The reason I need to set the user agent is because twitter keeps giving the "There was a login to your account @xxxx from a new device on Sep 10, 2024. Review it now"

I was trying to set user_agent to avoid this message.

You have a comment - https://github.com/d60/twikit/issues/169#issuecomment-2286465397 which is similar but there this seems to happen without setting user_agent explicitly, whereas in my it happens because I am trying to set it.

AKSMA commented 3 weeks ago

client=Client(language="en-US") async def main(): await client.login(auth_info_1=username, auth_info_2=email, password=password) asyncio.run(main()) I am getting the same error even with this. I am working on macos. How to resolve this error.

Szymjotek commented 3 weeks ago

I have the same issue

nisaayufirda commented 3 weeks ago

same issue here

brainzcode commented 1 week ago

If you are on Mac replace: client = Client('en-US')

with

client = Client( user_agent="Put Your User Agent Here" )

satyarthProplens commented 1 week ago

If you are on Mac replace: client = Client('en-US')

with

client = Client( user_agent="Put Your User Agent Here" )

I've used this solution but not still getting the same error. I'm on mac. My user agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

brainzcode commented 1 week ago

If you are on Mac replace: client = Client('en-US') with client = Client( user_agent="Put Your User Agent Here" )

I've used this solution but not still getting the same error. I'm on mac. My user agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Can you share your complete code and the complete error, I’ll like to run it and see where the problem is coming from.

let me also ask, did you turn your solution into an asynchronous solution?

EyalShechtman commented 5 days ago

If you are on Mac replace: client = Client('en-US') with client = Client( user_agent="Put Your User Agent Here" )

I've used this solution but not still getting the same error. I'm on mac. My user agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Can you share your complete code and the complete error, I’ll like to run it and see where the problem is coming from.

let me also ask, did you turn your solution into an asynchronous solution?

I'm in the same boat, my function is async and it seems like I'm doing everything right. Where can I send you the code?

Here is my code:

import asyncio from twikit import Client, TooManyRequests

Min_tweets = 10

username = 'XXXX' email = 'XXXX' password = 'XXXX'

client= Client( user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36' )

print(client)

print('got the client') async def main():

print('entered main')
await client.login(auth_info_1=username, auth_info_2=email, password=password)

tweets = await client.search_tweet('chatGPT', 'Latest')
print(tweets)
for tweet in tweets:
    print(tweet.text)
more_tweets = await tweets.next()

print('About to do main')

await main()