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

Auth error code 399 twikit v2.2.0 #281

Closed
rob11030o opened this issue Jan 6, 2025 · 12 comments
Closed

Auth error code 399 twikit v2.2.0 #281

rob11030o opened this issue Jan 6, 2025 · 12 comments

Comments

@rob11030o
Copy link

Using twikit v2.2.0 (latest)

await xclient.login(
    auth_info_1=USERNAME,
    auth_info_2=EMAIL,
    password=PASSWORD,
    totp_secret=TOTP_SECRET
)

getting:

Traceback (most recent call last):
  File "/Users/robin/Projects/python-lib/twitter/main2.py", line 33, in <module>
    asyncio.run(main())
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/robin/Projects/python-lib/twitter/main2.py", line 22, in main
    await xclient.login(
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/twikit/client/client.py", line 439, in login
    await flow.execute_task({
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/twikit/utils.py", line 88, in execute_task
    response, _ = await self._client.v11.onboarding_task(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/twikit/client/v11.py", line 90, in onboarding_task
    return await self.base.post(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/twikit/client/client.py", line 214, in post
    return await self.request('POST', url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/twikit/client/client.py", line 185, in request
    raise BadRequest(message, headers=response.headers)
twikit.errors.BadRequest: status: 400, message: "{"errors":[{"code":399,"message":"Incorrect. Please try again. g;173619650519173336:-1736196505414:ypaxvTcvdL0g48L0oIb4f6bK:9"}]}"
@perza007
Copy link

perza007 commented Jan 7, 2025

easiest way to login is extracting your auth_token and ct0 cookies and using set_cookie

client.set_cookies({ "auth_token": auth_token, "ct0": ct0 })

@nikssj
Copy link

nikssj commented Jan 7, 2025

easiest way to login is extracting your auth_token and ct0 cookies and using set_cookie

client.set_cookies({ "auth_token": auth_token, "ct0": ct0 })

thats all we need for cookies.json? Im trying to manually create in another device to avoid IP detecting

@cmj
Copy link

cmj commented Jan 7, 2025

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.

You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

@nikssj
Copy link

nikssj commented Jan 7, 2025

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.

You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

Thanks for your fast and valuable answer.

Its working.

@snowtank
Copy link

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.
You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

Thanks for your fast and valuable answer.

Its working.

can you tell me how can I get auth_token thank you!

@nikssj
Copy link

nikssj commented Jan 10, 2025

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.
You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

Thanks for your fast and valuable answer.
Its working.

can you tell me how can I get auth_token thank you!

Login via browser and extract from Browser console. It will appear on Application tab - Cookies

@perza007
Copy link

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.
You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

Thanks for your fast and valuable answer.
Its working.

can you tell me how can I get auth_token thank you!

Any cookie editing extension, i use EditThisCookie for chrome.

@snowtank
Copy link

Yes, also your session shouldn't be shown in a "session list" (known locations and devices) as far as I know, if you're using an existing cookie. It only tracks new logins.
You can check using this simple tool https://github.com/cmj/twitter-tools/blob/main/user/UserSessionsList.sh

Thanks for your fast and valuable answer.
Its working.

can you tell me how can I get auth_token thank you!

Login via browser and extract from Browser console. It will appear on Application tab - Cookies

thank you,I will try it

@snowtank
Copy link

this is my code it still doesn't work ,please help me thank you !!!
try:
client.set_cookies({"auth_token": auth_token, "ct0": ct0})
await client.login(
auth_info_1=USERNAME,
auth_info_2=EMAIL,
password=PASSWORD
)
except Exception as e:
print(e)

@tommhe14
Copy link

Because your code structure is completely wrong and not inline with what setting and loading cookies is actually supposed to do.

First log in, then set_cookies, later you can instead of logging in multiple times, creating a new session on your twitter account, Just load the cookies from said session and continue as usual.

auth token and ct0 has no place there, If you wish to sign in with a OTP it currently does not work.

@snowtank
Copy link

Because your code structure is completely wrong and not inline with what setting and loading cookies is actually supposed to do.

First log in, then set_cookies, later you can instead of logging in multiple times, creating a new session on your twitter account, Just load the cookies from said session and continue as usual.

auth token and ct0 has no place there, If you wish to sign in with a OTP it currently does not work.

Thank you for your answer. My current code has been modified to the same code as the example file, but I still cannot log in and return a 400 error. I have not logged in yet, and the following operations cannot be performed. Can you help me check if you really appreciate it

my code is

async def main():
# Asynchronous client methods are coroutines and
# must be called using await.
try:
# client.set_cookies({"auth_token": auth_token, "ct0": ct0})
await client.login(
auth_info_1=USERNAME,
auth_info_2=EMAIL,
password=PASSWORD
)
except Exception as e:
print(e)

asyncio.run(main())

this is return text
status: 400, message: "{"errors":[{"code":399,"message":"Incorrect. Please try again. g;173664909282282219:-1736649093167:46Z4E0fJWLGBhfaNEvawU0fq:9"}]}"

Thank you!

@d60
Copy link
Owner

d60 commented Jan 29, 2025

Fixed in version 2.2.2
https://github.com/d60/twikit/releases/tag/version2.2.2

@d60 d60 closed this as completed Jan 29, 2025
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

7 participants