TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

Access denied error (Video download)

Open sulynajimsj opened this issue 2 years ago • 8 comments

Fill Out the template :)

**When I try to download a video I get access denied when I print the object of video with .bytes()? Why is that?

ERROR IS GET:

b'<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD><BODY>\n<H1>Access Denied</H1>\n \nYou don't have permission to access "http://v16-webapp-prime.tiktok.com/video/tos/maliva/tos-maliva-ve-0068c799-us/c4895fafa0244a9b82fc58d016ed3682/?" on this server.<P>\nReference #18.97c44543.1676067610.a8d80cc\n</BODY>\n</HTML>\n'

Please add any relevant code that is giving you unexpected results.

def tiktokScrape(url):

	# Initialize the TikTokApi object
	tiktok_api = TikTokApi()

	#Get the id from the link
	id = url.split("/")[-1]

	print(id)
	video_bytes = tiktok_api.video(id=id).bytes()
	print(video_bytes)

	# Saving The Video
	with open('tiktok_video.mp4', 'wb') as output:
		output.write(video_bytes)

tiktokScrape("https://www.tiktok.com/@keytodiscipline_/video/7176704311873916203")

Expected behavior

A clear and concise description of what you expected to happen.

Error Trace (if any)

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

# Error Trace Here

Desktop (please complete the following information):

  • OS: [e.g. Windows 10]
  • TikTokApi Version [e.g. 5.0.0] - if out of date upgrade before posting an issue

Additional context

Add any other context about the problem here.

sulynajimsj avatar Feb 10 '23 22:02 sulynajimsj

same

PlsDrop avatar Feb 11 '23 10:02 PlsDrop

i have the same issue

DaniyalMg avatar Feb 13 '23 00:02 DaniyalMg

import random from TikTokApi import TikTokApi

did = str(random.randint(10000, 999999999))

    with TikTokApi(custom_device_id=did) as api:
        video = api.video(id=id)
        video_data = video.bytes()

        with open(f"out.mp4", "wb") as out_file:
            out_file.write(video_data)

DaniyalMg avatar Feb 13 '23 01:02 DaniyalMg

@davidteather it seems the original code generates too long custom_device_ids, f.ex.:

 if kwargs.get("generate_static_device_id", False):

            self._custom_device_id = "".join(

                random.choice(string.digits) for num in range(19)

when i changed that to f.ex. range(9), as @DaniyalMg shows in his comment, downloading worked

Scherenschnitt avatar Feb 13 '23 14:02 Scherenschnitt

@davidteather @DaniyalMg Fill Out the template :)

For some reason I keep getting this thread error when using the titkok api

I keep getting this error when I run the code I do not know why this happens with TikTokAPI

Error:

File "C:\Users\SulyS\OneDrive\Desktop\AiSearchv1\app2.py", line 17, in titkok("https://www.tiktok.com/@demonixslayer/video/7151993610303524123") File "C:\Users\SulyS\OneDrive\Desktop\AiSearchv1\app2.py", line 9, in titkok with TikTokApi(custom_device_id=did) as api: File "c:\users\sulys\appdata\local\programs\python\python38\lib\site-packages\TikTokApi\tiktok.py", line 159, in init self._initialize( File "c:\users\sulys\appdata\local\programs\python\python38\lib\site-packages\TikTokApi\tiktok.py", line 205, in _initialize self._browser = asyncio.get_event_loop().run_until_complete( File "c:\users\sulys\appdata\local\programs\python\python38\lib\asyncio\events.py", line 639, in get_event_loop raise RuntimeError('There is no current event loop in thread %r.'

**import streamlit as st from TikTokApi import TikTokApi import random

st.write("TikTok Scrape examples")

def titkok(link): did = str(random.randint(10000, 999999999)) with TikTokApi(custom_device_id=did) as api: video = api.video(id=id) video_data = video.bytes()

with open(f"out.mp4", "wb") as out_file:
    out_file.write(video_data)

if (2==2): titkok("https://www.tiktok.com/@demonixslayer/video/7151993610303524123")**

Code Goes Here

import streamlit as st from TikTokApi import TikTokApi import random

st.write("TikTok Scrape examples")

def titkok(link): did = str(random.randint(10000, 999999999)) with TikTokApi(custom_device_id=did) as api: video = api.video(id=id) video_data = video.bytes()

    with open(f"out.mp4", "wb") as out_file:
        out_file.write(video_data)

if (2==2): titkok("https://www.tiktok.com/@demonixslayer/video/7151993610303524123")

sulynajimsj avatar Mar 01 '23 00:03 sulynajimsj

import random from TikTokApi import TikTokApi

did = str(random.randint(10000, 999999999))


    with TikTokApi(custom_device_id=did) as api:
        video = api.video(id=id)
        video_data = video.bytes()

        with open(f"out.mp4", "wb") as out_file:
            out_file.write(video_data)

Didn't work for me, any other solution?

Omak2r3a avatar Apr 19 '23 15:04 Omak2r3a

Thanks for the fix Daniyal

sadiqkhan2022 avatar May 07 '23 16:05 sadiqkhan2022