davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.77k stars 965 forks source link

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

Open paul-puzzless opened 8 months ago

paul-puzzless commented 8 months ago

Describe the bug

I'm currently facing the following issue acquiring user video data: TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response

The buggy code

from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get(
    "ms_token", None
)  # set your own ms_token, think it might need to have visited a profile

async def user_example():
    async with TikTokApi() as api:
        await api.create_sessions(
            ms_tokens=[ms_token],
            num_sessions=1,
            sleep_after=3,
        )
        user = api.user("therock")

        async for video in user.videos(count=30):
            print(video)
            print(video.as_dict)

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

Expected behavior

Video information printed out as dict

Error Trace (if any)

2024-01-13 23:15:22,402 - TikTokApi.tiktok - ERROR - Got an unexpected status code: {'userInfo': {'user': {}, 'stats': {}, 'shareMeta': {}}}
2024-01-13 23:15:22,402 - TikTokApi.tiktok - ERROR - Got an unexpected status code: {'userInfo': {'user': {}, 'stats': {}, 'shareMeta': {}}}
Traceback (most recent call last):
  File "/Users/p/Repositories/content-downloader/__main__.py", line 27, in <module>
    asyncio.run(user_example())
  File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/p/Repositories/content-downloader/__main__.py", line 21, in user_example
    async for video in user.videos(count=30):
  File "/Users/p/Library/Caches/pypoetry/virtualenvs/content-downloader-LZhmm4ia-py3.11/lib/python3.11/site-packages/TikTokApi/api/user.py", line 112, in videos
    await self.info(**kwargs)
  File "/Users/p/Library/Caches/pypoetry/virtualenvs/content-downloader-LZhmm4ia-py3.11/lib/python3.11/site-packages/TikTokApi/api/user.py", line 87, in info
    self.__extract_from_data()
  File "/Users/p/Library/Caches/pypoetry/virtualenvs/content-downloader-LZhmm4ia-py3.11/lib/python3.11/site-packages/TikTokApi/api/user.py", line 204, in __extract_from_data
    data["userInfo"]["user"]["id"],
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'id'

Desktop:

Additional context

I've also tried to trigger this request manually. This is the output I get:

{"userInfo": {"user": {},"stats": {},"shareMeta": {}}}

This issue seems to be somehow related: https://github.com/davidteather/TikTok-Api/issues/1097

Yogabayu commented 8 months ago

same with me, any updates ?

Bringers commented 8 months ago

I get the same error on all of the examples except for the "get video information" about a specific video. Do you manage to succeed with the other examples?

jesse-moderwell commented 8 months ago

Same here

jpratt9 commented 8 months ago

Launch the browser with headless=False. You should see that it prompts for you to sign in. We'll probably need some custom playwright code to get around this prompt whenever it pops up.

angelopouloschristos commented 7 months ago

Temporary fix to it : in "tiktok.py" line 206, change headless=True, to false.