Skip to content
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

[BUG] - Video download example code not working #1226

Open
FrancescoLanthaler opened this issue Feb 17, 2025 · 0 comments
Open

[BUG] - Video download example code not working #1226

FrancescoLanthaler opened this issue Feb 17, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@FrancescoLanthaler
Copy link

I am encountering an issue when trying to download videos using the example provided in the documentation. When calling video.bytes(), I receive the following error:

The buggy code

import asyncio
from TikTokApi import TikTokApi
import os

ms_token = "XXX"

proxy = {
    "server": "http://XXX:XX",
    "username": "XXX",
    "password": "XXX",
}


async def download_videos():
    async with TikTokApi() as api:
        await api.create_sessions(
            ms_tokens=ms_token,
            num_sessions=1,
            sleep_after=3,
            browser=os.getenv("TIKTOK_BROWSER", "chromium"),
            proxies=[proxy],
        )

        video_bytes = await api.video(id="11111111").bytes()
        with open("video.mp4", "wb") as f:
            f.write(video_bytes)


if __name__ == "__main__":
    asyncio.run(download_videos())

Expected behavior

The script should successfully fetch and download the video.

**Error Trace **

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

Traceback (most recent call last):
  File "/Users/francesco/Documents/FH-Salzburg/Work/video_download/download.py", line 32, in <module>
    asyncio.run(download_videos())
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/local/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/Cellar/[email protected]/3.13.1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 720, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/francesco/Documents/FH-Salzburg/Work/video_download/download.py", line 26, in download_videos
    video_bytes = await api.video(id="7439089243546193174").bytes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/francesco/Documents/FH-Salzburg/Work/video_download/.venv/lib/python3.13/site-packages/TikTokApi/api/video.py", line 188, in bytes
    downloadAddr = self.as_dict["video"]["downloadAddr"]
                   ^^^^^^^^^^^^
AttributeError: 'Video' object has no attribute 'as_dict'

Desktop (please complete the following information):

  • OS: Macos 15.3
  • TikTokApi Version: 7.0.0
@FrancescoLanthaler FrancescoLanthaler added the bug Something isn't working label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant