Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
197 stars 25 forks source link

Tiktok Is Blocking Downloads #32

Closed liechtym closed 1 year ago

liechtym commented 1 year ago

Awesome library!

I wanted to ask if you were aware of Tiktok blocking downloads. I started getting the error as of Feb 10, 2023. It looks like Tiktok has added an extra layer of security for downloading videos. Have you been able reproduce this problem as well?

Error:

<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nYou don\'t have permission to access "http&#58;&#47;&#47;v16&#45;webapp&#45;prime&#46;us&#46;tiktok&#46;com&#47;video&#47;tos&#47;useast5&#47;tos&#45;useast5&#45;ve&#45;0068c004&#45;tx&#47;9135085813b14270a32e64aecff14792&#47;&#63;" on this server.<P>\nReference&#32;&#35;18&#46;17f5df17&#46;1676300641&#46;4b789411\n</BODY>\n</HTML>\n

Code:

async def save_video(video):
    async with aiohttp.ClientSession() as session:
        async with session.get(video.video.download_addr) as resp:
            return io.BytesIO(await resp.read())

with TikTokAPI() as api:
    video = api.video(url)

bytes = asyncio.run(save_video(video))
Russell-Newton commented 1 year ago

I haven't encountered this problem. The sample code in the docs for downloading videos is based on code from my discord bot, and it's still working as of 1030 am on 2/13.

It's possible you need a proxy, or maybe your download links are going stale if you're taking too long to download them. They're generated each time someone views a video, and they don't last very long. If your code looks exactly like the sample code, then the links probably aren't going stale.

liechtym commented 1 year ago

Hmm I am puzzled because for me it's not working on more than one machine with different network connections. Any other ideas I could look into?

liechtym commented 1 year ago

Using the exact code from your example, I got it to work. I'm not sure why my code got that error. Thanks for your help.

Russell-Newton commented 1 year ago

That's odd. I'm glad you got it working.

liechtym commented 1 year ago

It appears the difference is emulate_mobile=True. It doesn't work without it.