twikit icon indicating copy to clipboard operation
twikit copied to clipboard

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

Open RisenCrypto opened this issue 1 year ago • 8 comments

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.

RisenCrypto avatar Sep 10 '24 12:09 RisenCrypto

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.

AKSMA avatar Sep 10 '24 23:09 AKSMA

I have the same issue

SzymonJot avatar Sep 11 '24 19:09 SzymonJot

same issue here

nisaayufirda avatar Sep 15 '24 04:09 nisaayufirda

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

with

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

brainzcode avatar Sep 25 '24 01:09 brainzcode

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

satyarthProplens avatar Sep 27 '24 16:09 satyarthProplens

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?

brainzcode avatar Sep 27 '24 16:09 brainzcode

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()

EyalShechtman avatar Sep 30 '24 16:09 EyalShechtman

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()

I will try to reproduce your error using your code and drop a feedback here.

brainzcode avatar Oct 10 '24 12:10 brainzcode

try version 2.2.0

d60 avatar Dec 01 '24 11:12 d60