davidteather / TikTok-Api

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

[BUG] - Failed to run even hashtag_example i added ms_token #1162

Open vagvalas opened 3 months ago

vagvalas commented 3 months ago

I'm unable to run even the examples with an added ms_token, I'm not sure if i had done everything right but i cant seem to understand exactly if i had also to add a cookie, or how do i get a cookie except from ms_token. I think the line ms_token, None i had filled correctly.

I modified the example:


from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get("sySiUDTlgtCc9mZpdOuYuP1stjvSP8mgMSG3jQEDXBK6X86EuOqzLjjFAs8KMWVrg1G_8C7uTxm4We4_oDyjZidveAfd7lb5-DFhGFkaqsi8tRFnV7dYiIaPsxr0SFt6v-d6RSNE3JsNFqaYS8w=", None)  # set your own 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="coldplayathens")
        async for video in tag.videos(count=150):
            print(video)
            print(video.as_dict)

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

Error Trace (if any)

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

File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/vaggosval/Desktop/toktik/TikTok-Api/examples/hashtag_example.py", line 18, in <module>
    asyncio.run(get_hashtag_videos())
  File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/vaggosval/Desktop/toktik/TikTok-Api/examples/hashtag_example.py", line 12, in get_hashtag_videos
    async for video in tag.videos(count=150):
  File "/Users/vaggosval/Desktop/toktik/TikTok-Api/TikTokApi/api/hashtag.py", line 118, in videos
    resp = await self.parent.make_request(
  File "/Users/vaggosval/Desktop/toktik/TikTok-Api/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):

Additional context

Add any other context about the problem here.

jagl16 commented 3 months ago

Seems like related to https://github.com/davidteather/TikTok-Api/issues/1090

Easiest workaround for me on mac was to set headless=False for now.

vagvalas commented 3 months ago

I finally , and also using this help, and chatGPT finally made to make a script to fetch and port to yt_dlp and download all videos i need. BUT , as i undestand it only fetches till the public ones.. i mean, the hashtag has 2,000 videos, and even if im logged in and not logged in i can see through my browser 50 videos (45 sometimes) and the TikTok-Api it COMPLETES and finishes the script on 45 videos..

Is there any workaround on this? how to fetch more? as logged in?

zhangzyg commented 2 months ago

@jagl16 @vagvalas I faced the same issue in a sudden even when I switch headless=False
API sends is like: https://www.tiktok.com/api/challenge/item_list

but still receive empty response, is there some anti-scrape enhancement from tik-tok?

jagl16 commented 2 months ago

@zhangzyg I haven't tried it again in a few weeks, but wouldn't be surprised if tiktok did implement new anti scraping changes.

florifull commented 2 months ago

Any updates here?

@vagvalas would you be willing you share your new script for scraping by hashtag?