Skip to content

[BUG] - Comment extraction is not working #1255

@streylix

Description

@streylix

Describe the bug

Comment extraction via video.comments() consistently returns empty responses with error "TikTok returned an empty response. They are detecting you're a bot" despite using recommended stealth settings including user agent, viewport configuration, and various browser options. The API connection itself works (can fetch trending videos), but the comments endpoint specifically is blocked.

The buggy code

Please add any relevant code that is giving you unexpected results.

Preferably the smallest amount of code to reproduce the issue.

SET LOGGING LEVEL TO INFO BEFORE POSTING CODE OUTPUT

import logging
TikTokApi(logging_level=logging.INFO) # SETS LOGGING_LEVEL TO INFO
# Hopefully the info level will help you debug or at least someone else on the issue
import asyncio
import logging
from TikTokApi import TikTokApi

async def extract_comments():
    # Context options as suggested in other issues
    context_options = {
        'viewport': {'width': 1280, 'height': 1024},
        'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
    }
    
    api = TikTokApi(logging_level=logging.INFO)
    
    # Test with MS_TOKEN
    ms_token = "6Mfvbxa79fOMInATgwTJKBhUUVLKNiNMsqo3nw-VF-j5Ymu88o_FLRhYL6XKbKNELqOT2kBAaHVa53OBgVA1d6X2ACBfejsUgLLnKvdE6oYdMPOVGRFUtePy6w7HvQ6hBOlNazA="
    
    await api.create_sessions(
        ms_tokens=[ms_token],
        num_sessions=1,
        sleep_after=3,
        context_options=context_options,
        browser='webkit',  # Also tried 'chromium' and 'firefox'
        headless=True      # Also tried False
    )
    
    # This works - proving connection is valid
    print("Testing trending videos (this works):")
    async for video in api.trending.videos(count=1):
        video_dict = video.as_dict
        print(f"✅ Fetched video: {video_dict.get('id')}")
    
    # This fails - comment extraction
    print("\nTesting comment extraction (this fails):")
    video = api.video(id="7106672885863435566")
    video.url = "https://www.tiktok.com/@zachking/video/7106672885863435566"
    
    try:
        # This returns empty response
        async for comment in video.comments(count=5):
            print(f"Comment: {comment.as_dict}")
    except Exception as e:
        print(f"❌ Error: {e}")
    
    await api.close_sessions()

if __name__ == "__main__":
    asyncio.run(extract_comments())

Expected behavior

The video.comments() method should return comment objects with text, user information, and engagement metrics. Based on the documentation and previous versions, it should iterate through comments similar to how trending.videos() works.

Error Trace (if any)

Put the error trace below if there's any error thrown.

2025-08-27 23:21:01,427 - TikTokApi.tiktok - INFO - Creating sessions...
2025-08-27 23:21:05,123 - TikTokApi.tiktok - INFO - Created 1 sessions
Testing trending videos (this works):
✅ Fetched video: 7431216726046174494

Testing comment extraction (this fails):
❌ Error: None -> TikTok returned an empty response. They are detecting you're a bot, try some of these: headless=False, browser='webkit', consider using a proxy

Traceback (most recent call last):
  File "test_comments.py", line 38, in extract_comments
    async for comment in video.comments(count=5):
  File "/venv/lib/python3.13/site-packages/TikTokApi/api/video.py", line 264, in comments
    resp = await self.parent.make_request(
  File "/venv/lib/python3.13/site-packages/TikTokApi/tiktok.py", line 503, in make_request
    raise EmptyResponseException(result, "TikTok returned an empty response. They are detecting you're a bot, try some of these: headless=False, browser='webkit', consider using a proxy")
TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response. They are detecting you're a bot, try some of these: headless=False, browser='webkit', consider using a proxy

Desktop (please complete the following information):

  • OS: macOS 14.5 (Darwin 24.5.0)
  • TikTokApi Version: 7.1.0
  • Python Version: 3.13
  • Playwright Version: 1.54.0

Additional context

  • The same code successfully fetches trending videos, proving the session/connection works
  • Tried all recommended solutions from the error message:
    • headless=False - Still fails
    • browser='webkit' - Still fails (also tried chromium and firefox)
    • Using proxy - SOCKS5 proxies don't work with Playwright authentication
  • Tested with valid MS_TOKEN from browser cookies
  • Issue appears to be specific to the comments endpoint, not a general connection issue
  • video.info() also returns "invalid response structure" but with 200 status
  • This suggests TikTok has specifically hardened these endpoints against automation

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions