twikit icon indicating copy to clipboard operation
twikit copied to clipboard

Hit error 'This request looks like it might be automated. '

Open KazuyaFCB opened this issue 1 year ago • 7 comments

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?

KazuyaFCB avatar Aug 03 '24 16:08 KazuyaFCB

I just hit this too. However, searching and other interactions are fine

justin-dx avatar Aug 04 '24 00:08 justin-dx

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"},
}

david-lev avatar Aug 16 '24 11:08 david-lev

After update is already fixed for me

AritzUMA avatar Aug 17 '24 13:08 AritzUMA

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.

shubiao-yao avatar Feb 20 '25 03:02 shubiao-yao

Are there any friends who solved the problem?

Mucahitakin avatar Feb 25 '25 07:02 Mucahitakin

I also am facing this error. All I'm seeking to do is infrequently post tweets. Curious if anyone has found a workaround. Thanks!

j-inc avatar Aug 26 '25 16:08 j-inc