Code Monkey home page Code Monkey logo

Comments (13)

VitoLin avatar VitoLin commented on June 10, 2024 12

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

from tiktok-api.

dungdl avatar dungdl commented on June 10, 2024 5

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

from tiktok-api.

algoprofit8 avatar algoprofit8 commented on June 10, 2024 1

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

from tiktok-api.

Xarbenence avatar Xarbenence commented on June 10, 2024

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

from tiktok-api.

gabrielrosendo avatar gabrielrosendo commented on June 10, 2024

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"

from tiktok-api.

Xarenn avatar Xarenn commented on June 10, 2024

I have the same issue...

from tiktok-api.

Xarenn avatar Xarenn commented on June 10, 2024

Nope, for comments still doesn't work

from tiktok-api.

calvin5walters avatar calvin5walters commented on June 10, 2024

@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

from tiktok-api.

jpratt9 avatar jpratt9 commented on June 10, 2024

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

from tiktok-api.

calvin5walters avatar calvin5walters commented on June 10, 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

from tiktok-api.

jpratt9 avatar jpratt9 commented on June 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

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

from tiktok-api.

carol-he avatar carol-he commented on June 10, 2024

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

from tiktok-api.

cloudengineer89 avatar cloudengineer89 commented on June 10, 2024

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

from tiktok-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.