Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Error encountered getting comments: TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response #1097

Open
binaryplatitude opened this issue Dec 19, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@binaryplatitude
Copy link

binaryplatitude commented Dec 19, 2023

Describe the bug

Tiktok throwing a fit and not giving me my comments.

The buggy code

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

Preferably the smallest amount of code to reproduce the issue.

from TikTokApi import TikTokApi
import asyncio
import os


video_id = 7248300636498890011
ms_token = os.environ.get("ms_token", None)  # set your own ms_token


async def get_comments():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        video = api.video(id=video_id)
        count = 0
        async for comment in video.comments(count=10):
            print(comment)
            print(comment.as_dict)


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

Expected behavior

Comments printed out

Error Trace (if any)

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

Traceback (most recent call last):
File "c:\Users\user\Documents\Python Project Workspace\Tiktok Data\commentTester.py", line 23, in
asyncio.run(get_comments())
File "C:\Users\user\anaconda3\envs\scapersecondenv\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\user\anaconda3\envs\scapersecondenv\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "c:\Users\user\Documents\Python Project Workspace\Tiktok Data\commentTester.py", line 17, in get_comments
async for comment in video.comments(count=10):
File "C:\Users\user\anaconda3\envs\scapersecondenv\lib\site-packages\TikTokApi\api\video.py", line 263, in comments
resp = await self.parent.make_request(
File "C:\Users\user\anaconda3\envs\scapersecondenv\lib\site-packages\TikTokApi\tiktok.py", line 430, in make_request
raise EmptyResponseException(result, "TikTok returned an empty response")
TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response

Desktop (please complete the following information):

  • OS: [e.g. Windows 10]
  • TikTokApi Version [e.g. 5.0.0] - 6.2.0

Additional context

Its an older bug sir, but it checks out.

@binaryplatitude binaryplatitude added the bug Something isn't working label Dec 19, 2023
@algoprofit8
Copy link

Looks like api is broken, i tried manualy do request to get user info https://www.tiktok.com/api/user/detail/?uniqueId=therock&msToken=token and its really return empty response

@Xarbenence
Copy link

I am getting this same exception on Mac Vetura 13.3 with the basic "trending videos" example.

`from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get("ms_token", None) # get your own ms_token from your cookies on tiktok.com

async def trending_videos():
async with TikTokApi() as api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
async for video in api.trending.videos(count=30):
print(video)
print(video.as_dict)

if name == "main":
asyncio.run(trending_videos())`

Traceback:

/Users/alexsharper/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 warnings.warn( Traceback (most recent call last): File "/Users/alexsharper/Documents/Lancing/Etai/TikTokBot/ex1.py", line 15, in <module> asyncio.run(trending_videos()) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Users/alexsharper/Documents/Lancing/Etai/TikTokBot/ex1.py", line 10, in trending_videos async for video in api.trending.videos(count=30): File "/Users/alexsharper/Library/Python/3.9/lib/python/site-packages/TikTokApi/api/trending.py", line 43, in videos resp = await Trending.parent.make_request( File "/Users/alexsharper/Library/Python/3.9/lib/python/site-packages/TikTokApi/tiktok.py", line 430, in make_request raise EmptyResponseException(result, "TikTok returned an empty response") TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response

@gabrielrosendo
Copy link

Any updates on this? Running the basic example and I was able to get a response once but after that I get "TikTok returned an empty response"

@Xarenn
Copy link

Xarenn commented Jan 9, 2024

I have the same issue...

@dungdl
Copy link

dungdl commented Jan 10, 2024

I've tried this any it work: in the api.create_sessions you should add the param headless=False, this will open the playwright browser on your computer and then you can have the response. Full command:

api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False)

It's a bit annoying but preventing the Empty Response error

@Xarenn
Copy link

Xarenn commented Jan 10, 2024

Nope, for comments still doesn't work

@VitoLin
Copy link

VitoLin commented Jan 14, 2024

I've tried this any it work: in the api.create_sessions you should add the param headless=False, this will open the playwright browser on your computer and then you can have the response. Full command:

api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False)

It's a bit annoying but preventing the Empty Response error

This can also be fixed by setting the user_agent and viewport in the context_options while remaining headless

import asyncio
import os

ms_token = os.environ.get(
    "ms_token", None
) 
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'
}

async def trending_videos():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, context_options=context_options)
        async for video in api.trending.videos(count=30):
            print(video)
            print(video.as_dict)

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

This also seems to bypass the need to have a ms_token

@calvin5walters
Copy link

@VitoLin This worked for me for a few runs, then it went back to the "EmptyResponseException: None -> TikTok returned an empty response" error. Any idea why it only works periodically? Is there a rate limit or something? Thanks

@jpratt9
Copy link

jpratt9 commented Jan 29, 2024

Has anyone tried rotating the ms_token or proxy we go through? It might be bot/scraping-detection on TikTok's part.

@calvin5walters
Copy link

calvin5walters commented Jan 29, 2024

Has anyone tried rotating the ms_token or proxy we go through? It might be bot/scraping-detection on TikTok's part.

What do you mean by "rotating" the ms_token? And how would one do that? Thanks! @jpratt9

@jpratt9
Copy link

jpratt9 commented Jan 30, 2024

I've tried this any it work: in the api.create_sessions you should add the param headless=False, this will open the playwright browser on your computer and then you can have the response. Full command:

api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False)

It's a bit annoying but preventing the Empty Response error

This can also be fixed by setting the user_agent and viewport in the context_options while remaining headless

import asyncio
import os

ms_token = os.environ.get(
    "ms_token", None
) 
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'
}

async def trending_videos():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, context_options=context_options)
        async for video in api.trending.videos(count=30):
            print(video)
            print(video.as_dict)

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

This also seems to bypass the need to have a ms_token

This only seems to work for me with api.trending, not api.user

@carol-he
Copy link

I'm still getting EmptyResponse no matter which one I try, even with headless=False

@cloudengineer89
Copy link

Finally, I got a response. Maybe someone can help me out with headless=False. How not to show the pop-up window?
Without this attribute, I got error: TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests