d60/twikit

Forbidden: status: 403,

Closed this issue · 11 comments

I got this error. Can not tweet


Forbidden Traceback (most recent call last)
in <cell line: 1>()
----> 1 client.create_tweet(
2 text='Example Tweet'
3 )

2 frames
/usr/local/lib/python3.10/dist-packages/twikit/client.py in create_tweet(self, text, media_ids, poll_uri, reply_to, conversation_control)
701 'features': FEATURES,
702 }
--> 703 response = self.http.post(
704 Endpoint.CREATE_TWEET,
705 data=json.dumps(data),

/usr/local/lib/python3.10/dist-packages/twikit/http.py in post(self, url, **kwargs)
52
53 def post(self, url, **kwargs) -> httpx.Response:
---> 54 return self.request('POST', url, **kwargs)
55
56 def _remove_duplicate_ct0_cookie(self) -> None:

/usr/local/lib/python3.10/dist-packages/twikit/http.py in request(self, method, url, **kwargs)
34 raise Unauthorized(message)
35 elif status_code == 403:
---> 36 raise Forbidden(message)
37 elif status_code == 404:
38 raise NotFound(message)

Forbidden: status: 403, message: ""

d60 commented

You may not be logged in or your cookies may be disabled.
Please log in first.
Please see the documentation for login instructions.
https://twikit.readthedocs.io/en/latest/twikit.html#twikit.client.Client.login

i was not getting this error until I started hosted the script online. Cookies may be disabled means?

d60 commented

Yes, that is a possibility, please try re-logging in.

same error. Can you help me enable the cookie

does this have to do anything with hosting on the terminal not on a vps as I hosted on a terminal based hosting and then it started showing this error

figured it out was not using load_cookies was logging so much that suspicious attempt mail by twitter. Please login through incognito once and complete the security questions then try logging in. and use cookies thank you

d60 commented

I was able to reproduce the same bug when I tried it on Google Colab.
It seems that Twitter is requesting email verification because the user attempted to log in under a different IP address. I'm currently working on resolving this bug.
Specifically, I plan to implement a process where the login method is called, and if Twitter requests email verification, I'll prompt the user to input the verification code using the input function, and then proceed with the login.

If you have any suggestions, please let me know.

yeah that would be great. How much time will it take cause I need to host this for my twitter dm notifier

and would be mind sharing your discord I have a few suggestions to make not regarding this issue

d60 commented

Early would be in about 6 hours, and late I think it will take until tomorrow.

d60 commented

It has been discovered that accounts can be authenticated using stored cookies, even for different IP addresses.
Therefore, instead of using client.login, use client.load_cookies('path_to_cookies').
@tnajun