Hit error 'This request looks like it might be automated. '
It hits error in the line: await client.create_tweet(comment_content['text'], reply_to=new_tweet.id, media_ids=comment_media_ids)
Error:
twikit.errors.CouldNotTweet: {'message': "Authorization: This request looks like it might be automated. To protect our users from spam and other malicious activity, we can't complete this action right now. Please try again later. (226)", 'locations': [{'line': 18, 'column': 3}], 'path': ['create_tweet'], 'extensions': {'name': 'AuthorizationError', 'source': 'Client', 'code': 226, 'kind': 'Permissions', 'tracing': {'trace_id': '282baea6b4e205d1'}}, 'code': 226, 'kind': 'Permissions', 'name': 'AuthorizationError', 'source': 'Client', 'tracing': {'trace_id': '282baea6b4e205d1'}}
My source code:
# Function to upload media and check file type
async def upload_and_check(file_path : str):
with open(file_path, 'rb') as f:
binary = f.read()
kind = filetype.guess(binary)
if kind is None:
raise Exception(f"Cannot guess file type for {file_path}")
return await client.upload_media(file_path, wait_for_completion=True)
async def random_delay():
print("Wait 10-20 seconds...\n")
delay = random.uniform(10, 20)
await asyncio.sleep(delay)
"""
Sample for post_content:
{
"text": "Some post content",
"images": [
"media\\20240803231338\\test.jpg"
],
"videos": []
}
Sample for comment_contents:
{
"text": "Some comment content",
"images": [],
"videos": ["media\\20240803231338\\test.mp4"]
}
"""
async def create_post_and_comment(post_content: dict[str, any], comment_contents: list):
post_media_ids: List[str] = []
for image in post_content['images']:
post_media_ids.append(await upload_and_check(image))
for video in post_content['videos']:
post_media_ids.append(await upload_and_check(video))
new_tweet = await client.create_tweet(post_content['text'], media_ids=post_media_ids)
print(f"Created new post: {post_content['text']}\n")
await random_delay()
# Create comments under the new tweet
for comment_content in comment_contents:
comment_media_ids: List[str] = []
for image in comment_content['images']:
comment_media_ids.append(await upload_and_check(image))
for video in comment_content['videos']:
try:
comment_media_ids.append(await upload_and_check(video))
except Exception as e:
print(f"Error uploading video: {e}")
continue # Skip this video and continue
await client.create_tweet(comment_content['text'], reply_to=new_tweet.id, media_ids=comment_media_ids)
print(f"Created new comment: {comment_content['text']}\n")
await random_delay()
# Log out
await client.logout()
Is there any solution?
I just hit this too. However, searching and other interactions are fine
Same for me. any solution?
twikit.errors.CouldNotTweet: {
"message": "Authorization: This request looks like it might be automated. To protect our users from spam and other malicious activity, we can't complete this action right now. Plea se try again later. (226)",
"locations": [{"line": 18, "column": 3}],
"path": ["notetweet_create"],
"extensions": {
"name": "AuthorizationError",
"source": "Client",
"code": 226,
"kind": "Permissions",
"tracing": {"trace_id": "205xxxxxxxfca"},
},
"code": 226,
"kind": "Permissions",
"name": "AuthorizationError",
"source": "Client",
"tracing": {"trace_id": "2053xxxxxdfbfca"},
}
After update is already fixed for me
When I use the twikit 2.3.3 version of the code to call the create_tweet method, this error will occasionally appear, but I can succeed by retrying 1-2 times after an interval of 2-3 seconds. Error code: 226 Error message: Authorization: This request looks like it might be automated.
Are there any friends who solved the problem?
I also am facing this error. All I'm seeking to do is infrequently post tweets. Curious if anyone has found a workaround. Thanks!