Open arhen opened 3 months ago
This happens to me as well when I run in headless mode, if I set headless to false it works perfectly fine.
This happens to me as well when I run in headless mode, if I set headless to false it works perfectly fine.
It doesn't work for me.
I have same issue with this, I just copy the content of https://github.com/davidteather/TikTok-Api/blob/main/examples/user_example.py file and run in my local, and it thrown me the TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response
my local file:
from TikTokApi import TikTokApi
import asyncio
ms_token = 'my-token'
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("sana_sanananoda")
user_data = await user.info()
print(user_data)
async for video in user.videos(count=30):
print(video)
print(video.as_dict)
async for playlist in user.playlists():
print(playlist)
if __name__ == "__main__":
asyncio.run(user_example())
I don't know what happening.
My stacktrace:
Traceback (most recent call last):
File "/Users/ngoctientran/Desktop/crawler-tiktok/test.py", line 24, in <module>
asyncio.run(user_example())
File "/Users/ngoctientran/.pyenv/versions/3.10.3/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/ngoctientran/.pyenv/versions/3.10.3/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/Users/ngoctientran/Desktop/crawler-tiktok/test.py", line 12, in user_example
user_data = await user.info()
File "/Users/ngoctientran/Desktop/crawler-tiktok/venv/lib/python3.10/site-packages/TikTokApi/api/user.py", line 76, in info
resp = await self.parent.make_request(
File "/Users/ngoctientran/Desktop/crawler-tiktok/venv/lib/python3.10/site-packages/TikTokApi/tiktok.py", line 451, in make_request
raise EmptyResponseException(result, "TikTok returned an empty response")
TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response
This API works in some network environments but does not work in others.
how to fix it it was working couple of months fine
@davidteather really need help with this bug
Seems like it is working after I change my IPs. Is it related to proxies, idk.
@arhen You mean you changed your machines physical address or just a proxy of any type?
Fetching accounts videos worked super fine for me, until last week where it started throwing the error. I was using TikTokApi 6.2.0 version the whole time
it still not working for me
@Gereks123 @zakrian07 did anyone find the answer?
@Gereks123 No, just changes my computer public ips
I tried with multiple different IPs, but it doesn't work - even thought it worked fine before.
It there anything we can do to find the cause for this?
Hey, I have observed some strange behavior in this regard. Normaly i use xfvb-run to use the TikTokAPI headless. But 2 weeks ago it stops with the "TikTok returned an empty response". Today i tried to debug with no real success even not headless. BUT when the window pop up there ( not headless), and i interact with the window ( scroll a littl bit or accept/discline the cookie) it worked again! But only with chromium. (update: some mouse hover is enough) Its not a solution for an automatic script but maybe we can workaround with it ( i don't know how) Can somebody confirm this, too ?
Okay short update: I add
time.sleep(10)
await page.mouse.move(0,0)
await page.mouse.move(0,100)
below await page.goto(url)
in tiktok.py and now it works again. ( maybe need some tuning). even in xvfb
time.sleep(10) await page.mouse.move(0,0) await page.mouse.move(0,100)
Woaaah, It works!!!!!!!
can you explain your POV why thats problem occurs and why the solution above resolve the problem.
downgrade playwright using pip install playwright==1.37.0 and run playwright install im getting same issue can any body help me to fix it
@davidteather thisi s a blocker issue need fix it really need your input as my tool is down from coupe of weeks now
@arhen
time.sleep(10) await page.mouse.move(0,0) await page.mouse.move(0,100)
Woaaah, It works!!!!!!!
can you explain your POV why thats problem occurs and why the solution above resolve the problem.
Hey, i guess it's some security "feature" from tiktok against bots. My first try was page scrolling but this doesn't work. I only noticed in non-headless mode that my script no longer threw errors after a mouse movement. It was pure luck. And the lines then rebuild this behavour, wait until the page has built up and then “move” the mouse.
@arhen
time.sleep(10) await page.mouse.move(0,0) await page.mouse.move(0,100)
Woaaah, It works!!!!!!! can you explain your POV why thats problem occurs and why the solution above resolve the problem.
Hey, i guess it's some security "feature" from tiktok against bots. My first try was page scrolling but this doesn't work. I only noticed in non-headless mode that my script no longer threw errors after a mouse movement. It was pure luck. And the lines then rebuild this behavour, wait until the page has built up and then “move” the mouse.
It could be the bot's detection system. I'm not entirely sure how it works but maybe if no action has happened within a small timeframe it's automatically detected as a bot??
It could be the playwright itself, maybe TikTok detects some patterns that resemble the bots behaviour and automatically denies access?
Also, the sleep()
and mouse.move()
worked like a charm! Ty mate!
downgrade playwright using pip install playwright==1.37.0 and run playwright install im getting same issue can any body help me to fix it
You're not using the sleep()
function in the provided picture.
I think someone need to make a PR for this. @xXZaretXx
I think someone need to make a PR for this. @xXZaretXx
@arhen yes, but i hope somebody would improve my little "hacky" workaround. :sweat_smile:
I think someone need to make a PR for this. @xXZaretXx
@arhen yes, but i hope somebody would improve my little "hacky" workaround. 😅
Bring @davidteather here
wdyt about the hackaround
.
TLDR; Seems like for specific user.video api, default playwright interaction is not enough.Sometimes it works, and mostly throw the error this issued said above.
With default interactions, I got blocked and can access the video again after several hours or even days. From @xXZaretXx hackaround
i can tested that this method works perfectly and I already have automated bot that grab videos of som users every hours since last week.
I think someone need to make a PR for this. @xXZaretXx
@arhen yes, but i hope somebody would improve my little "hacky" workaround. 😅
Bring @davidteather here wdyt about the
hackaround
.TLDR; Seems like for specific user.video api, default playwright interaction is not enough.Sometimes it works, and mostly throw the error this issued said above.
With default interactions, I got blocked and can access the video again after several hours or even days. From @xXZaretXx
hackaround
i can tested that this method works perfectly and I already have automated bot that grab videos of som users every hours since last week.
Can confirm on my side, I'm scraping around 100+ accounts daily and this workaround fixed the problem for me.
EDIT: wording
Everyone on this thread, maybe check out this as well! https://github.com/davidteather/TikTok-Api/issues/1090
I'm running version 6.2.0 for the TikTokAPI with headless=False
Playwright version is 1.43.0.
ALSO, check your msTokens, they expire at a certain time and I had an incident one time where my code was not working due to the expired msToken. The API itself sometimes has issues with fetching the token from the browser itself.
Create an array of msTokens and just feed it to the create_sessions
method
Example:
`ms_tokens = [
"token_1", "token_2"
]
await api.create_sessions(ms_tokens=ms_tokens, num_sessions=1, sleep_after=3, headless=False)
Hi I already add this solution but still cannot get a data from tiktok. :(
Okay short update: I add
time.sleep(10) await page.mouse.move(0,0) await page.mouse.move(0,100)
below
await page.goto(url)
in tiktok.py and now it works again. ( maybe need some tuning). even in xvfb
My code
Error
@Warhead007 Which Browser do you use? I'm using chromium (create_sessions)
maybe you need to update your ms_token
Hi @xXZaretXx ,
I using a chromium. And can you explain how to get and update a ms_token? I'm a new to this project. Thank you.
Hi @xXZaretXx ,
I using a chromium. And can you explain how to get and update a ms_token? I'm a new to this project. Thank you.
You can get the ms_token by going to your actual browser and then navigate to tiktoks actual page.
Then open your developer tools and look for a cookie named ms_Token or something like that.
Also, looking at the picture, when you create your tiktok session, use the parameter "headless=False"
Hi, @Gereks123, @arhen , @xXZaretXx.
Have you been able to download the videos? My code can get the information about the videos, but when I try to download them, it says access denied. I modified the tiktok.py
file with the modification suggested in this discussion, but I still can't download the videos.
If you can, how do you download them?
Hi I already add this solution but still cannot get a data from tiktok. :(
Okay short update: I add
time.sleep(10) await page.mouse.move(0,0) await page.mouse.move(0,100)
below
await page.goto(url)
in tiktok.py and now it works again. ( maybe need some tuning). even in xvfbMy code
Error
Check you ms_token, try to change to a new one.
Hello! I tried your method at the date of this comment and it still does not work, we will have to find a way to prevent it from detecting it as a bot, as it seems to find the user (in my case) but when entering it comes out, it must be that it is trying to access some links so quickly or robustly that it detects it as a bot.
I'm running: Python: 3.12, TikTokApi: 6.5.2 with the given changes in this discussion Playwright: 1.39.0 OS: Windows 11
Everything works perfectly for me :/
Yeah! It seems to be working since I just tested it and it works but I don't know if it works with the changes made by the partner.
EDIT > Stopped working xd only tried it once with the example code
Yeah! It seems to be working since I just tested it and it works but I don't know if it works with the changes made by the partner.
EDIT > Stopped working xd only tried it once with the example code
Always make sure there aren't any dependencies interfering with you code. Always use a virtual enviornment for a fresh start.
When installing the TikTokApi, install pip install playwright==1.39.0
and then run python -m playwright install
depending on your OS, you might have to use "python3". On windows "python -m playwright install" should be enough
Describe the bug
Like the title, if you runt the code example "user_example" you will get the `TikTokApi.exceptions.EmptyResponseException: None -> TikTok returned an empty response.
The buggy code in example.user_example.py, this below code related to the error.
It means, user.info is working as expected but the videos from the user is not.
SET LOGGING LEVEL TO INFO BEFORE POSTING CODE OUTPUT