-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Video Downloading Error 403 #35
Comments
I'm not experiencing this problem, so I don't have a good way to debug it. I need some more information:
|
Related to #24 |
my code: |
I am also getting a 403 error. My code:
|
Is there any resolution? Thanks! |
I haven't had a whole lot of time to try to debug this, but I can share my initial thoughts: It's likely you may need to pass the cookies TikTokPy stores to aiohttp or requests. @alejandroarmas can you try modifying your code to have this: async with AsyncTikTokAPI(emulate_mobile=False, navigation_retries=3, navigation_timeout=60) as api:
async for video in user.videos:
dwn_link = await self.save_video(video, {cookie['name']: cookie['value'] for cookie in api.context.cookies()})
...
async def save_video(self, video: Video, cookies={}):
async with aiohttp.ClientSession(cookies=cookies) as session:
async with session.get(video.video.download_addr) as resp:
print(f'{resp=}') Note the changes here pass the api's cookies to the client session. @alexempie can you try changing your code to use response = requests.get(video.video.download_addr, cookies={cookie['name']: cookie['value'] for cookie in api.context.cookies()}) Note the change here passes the api's cookies to the If these changes work, I can update the documentation to include the fix. |
@Russell-Newton
I modified it a little bit: And then it worked. That is, the cookies that were used in the API I passed to the session. And the cookies themselves look like this: But the answer was still: Access Denied. Then I checked how it worked on the TT site itself. And there I realized that the direct link to the video only opens if it is opened by the same cookies as the normal video link. And there I saw one cookie that does not appear in And if we look at the cookies I wrote, we see that everything is there except s_v_web_id. I don't know why it's not issued when using api.context.cookies(). But I think sending this cookie in a session would solve the problem, or send the same cookie in both api and session initially. |
Every time a video or user page is loaded, TikTokPy clears its cookies. It's possible that s_v_web_id doesn't consistently get populated every visit. I probably need to adjust the cookie management. I don't have a whole lot of time in the next couple of days, given I'm a full time masters student, but I'll try to address this soon. |
After looking into it a bit, For whatever reason, I seem to be completely unable to recreate this issue consistently. On my end, looking at the cookies in my browser (I used a VPN connecting to an IP in Europe, Asia, and a different location in the Americas), and it looks like the only cookies that are required are I suspect these tokens are related to the download link, and any change in either makes the video not downloadable. Could you try copying over only those 4 cookies and seeing if that makes any difference? Something like: await self.save_video(video, {cookie["name"]: cookie["value"] for cookie in await api.context.cookies() if cookie["name"] in ("msToken", "ttwid", "tt_chain_token", "tt_csrf_token")}) If that doesn't work, you may need to use a VPN. |
It turned out to be much simpler and more obvious. You follow the link to the video and do the following
Send a GET request to the link from src with the cookie and header It's roughly like this:
|
I'll add this to the documentation ASAP! Thank you for the help @papayyg. I'll reference this thread and your account when I add it. |
Include extra note that can help resolve 403 errors when downloading videos
This has been added to the documentation: https://tiktokpy.readthedocs.io/en/stable/users/usage.html#download-videos-and-slideshows I'm closing the issue because it's been finished. |
Hi, @Russell-Newton and @papayyg, I followed your example, but I still got the access denied error. Could you please help? Here is the code:
Here is the error message:
|
@jinfu-leng Have you tried using a proxy and/or VPN? |
They seem to have changed something. Now I can’t access the direct link in any way, it doesn’t work with vpn either |
I'll see what I can find out. Once again, it's working fine on my end in the US, but I may be able to figure something out. |
It looks like TikTok is now validating the X-Bogus parameter now, and from what I can tell this is generated right before fetching based on the query parameters. I'll keep looking into this. |
* Create functions for executing API calls of 4 kinds: * comment/list/ - video comments * post/item_list/ - user posts * challenge/item_list/ - popular videos tagged with a challenge * related/item_list/ - videos related to this one * Opens up potential future resolutions for #35, #38, #40, #43, and #44
I have same problem
code:
|
This may be fixed in version 0.2.4 with the video |
Cannot download any video by down_addr from challenge collection. It returns 403 Forbidden error
for video in challenge.videos
requests.get(video.video.download_addr)
How to fix that?
The text was updated successfully, but these errors were encountered: