davidteather / TikTok-Api

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

Getting EmptyResponseException #1150

Closed ExtraneousFalcon closed 6 months ago

ExtraneousFalcon commented 6 months ago

Describe the bug

I tried the hashtag example but it doesn't work.

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
# Code Goes Here
from TikTokApi import TikTokApi
import asyncio
import os

ms_token = "W6YDsuiaNCLnK8P9WSMB-__SltPyDu7ioVqNi1-iLaI7RBLDQgN-EyAYcrXUMVgVFOCsOGbs6cOrj1wBXLkkpqJskaWLwuraNhun0vNB9x8qmVwdSFHPJGFOUVziYYvaJTQLJBM0yf3PM2xZ"
print(ms_token)
async def get_hashtag_videos():
    async with TikTokApi() as api:
        await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
        tag = api.hashtag(name="brainrot")
        async for video in tag.videos(count=30):
            print(video)
            print(video.as_dict)

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

Expected behavior

No errors.

Error Trace (if any)

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

# Error Trace Here
Traceback (most recent call last):
  File "/Users/saianoopavunuri/Documents/cs_projects/tiktok_brainrot/main.py", line 17, in <module>
    asyncio.run(get_hashtag_videos())
  File "/Users/saianoopavunuri/miniforge3/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/saianoopavunuri/miniforge3/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/saianoopavunuri/Documents/cs_projects/tiktok_brainrot/main.py", line 11, in get_hashtag_videos
    async for video in tag.videos(count=30):
  File "/Users/saianoopavunuri/Documents/cs_projects/tiktok_brainrot/venv/lib/python3.10/site-packages/TikTokApi/api/hashtag.py", line 108, in videos
    await self.info(**kwargs)
  File "/Users/saianoopavunuri/Documents/cs_projects/tiktok_brainrot/venv/lib/python3.10/site-packages/TikTokApi/api/hashtag.py", line 71, in info
    resp = await self.parent.make_request(
  File "/Users/saianoopavunuri/Documents/cs_projects/tiktok_brainrot/venv/lib/python3.10/site-packages/TikTokApi/tiktok.py", line 441, 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):

Gyom03 commented 6 months ago

Same error here

SunnyChopra7 commented 6 months ago

try this @ExtraneousFalcon await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False)

ExtraneousFalcon commented 6 months ago

try this @ExtraneousFalcon await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, headless=False)

That worked. Thank you!