Comments (6)
I understand now! In fact, the suggested correction has already been uploaded.
from twikit.
I forgot to close this issue. Sorry for the confusion!
@ShoGinn @itsManeka
from twikit.
I think that any dialog/examination of code is beneficial and shows that your efforts are being acknowledged so apologies are unnecessary!
from twikit.
That's hilarious ;) I'll have to pick on @d60 for not closing this, then!
I'll close it with this comment!!!
Good find @itsManeka
from twikit.
Just use client.set_cookies({}, True)
The first arg is te cookies (se {} to avoid) and the second arg is a flag to clear cookies.
from twikit.
I understand there is a way to clear cookies.
Lets use this scenario:
First Program Run:
login, save cookies.
Second Program Run:
note that cookies are saved and use saved cookies (using set_cookies)
get_tweets
etc. works fine
Third Program Run:
note that cookies are saved. Use saved cookies (using set_cookies)
get_tweets
throws an error for Unauthorized
This is where you are saying to run, then
.set_cookies(clear_cookies=true)
Real case.
.login()
and cookies are used anyway... so you have to.
This is my current code:
def login_with_credentials(twikit_client: Client, mongodb_client: MongoDBClient, app_settings: Settings) -> bool:
"""Login to X using the provided credentials."""
# Check to make sure the authentication information is provided
if not app_settings.x_username or not app_settings.x_email or not app_settings.x_password.get_secret_value():
raise ValueError("X credentials are missing or incomplete.")
logger.info("Logging in to X...")
twikit_client.http.client.cookies.clear() # TODO: Remove this once the twikit library is updated
try:
twikit_client.login(
auth_info_1=app_settings.x_username,
auth_info_2=app_settings.x_email,
password=app_settings.x_password.get_secret_value(),
)
logger.info("Successfully logged in to X.")
store_cookies(mongodb_client, twikit_client)
return True
except Exception as e:
logger.error(f"Error logging in to X: {e}")
logger.error("Please check your X credentials and run the program again.")
return False
Because the .login()
uses the HTTP engine, and if you have set cookies, it will always attempt to use cookies.
I hope I have explained why clearing cookies in .login()
is essential because of the HTTP engine's nature.
from twikit.
Related Issues (20)
- How post rate limit works? HOT 2
- async refactor
- list index out of range on client login HOT 2
- Error when tweeting a video HOT 11
- forbidden 403 HOT 1
- Feature Request: Implement Refresh Token Functionality
- twikit.errors.BadRequest: status: 400 HOT 2
- Counts Not Respected When Retrieving Tweets HOT 1
- get_trends() easily got KeyError 'trend' when using category other than trending
- When trying to create a tweet and adding a video to the tweet, it prompts: Error code 324 HOT 1
- get_tweet_by_id() throws IndexError
- Fetching posts HOT 1
- pool HOT 1
- Can I retrieve the number of tweets without an account? HOT 1
- Login method support TOTP code. HOT 1
- rate limitations HOT 6
- monitor reply,like tweets or retweet? HOT 4
- Auto Phone Number
- Login is not working HOT 1
- Unable to get follower counts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twikit.