Skip to content

Some Unicode / Persian filename causes FileNotFoundError in tempfile.mkstemp during download #14

Description

@esmaeelE

Describe the bug

Downloading videos with Persian (Farsi) titles fails with a FileNotFoundError in Python's tempfile.mkstemp() when using the wget module.

Consider download this file by apyrat

https://www.aparat.com/v/u75537l?playlist=289610

To Reproduce

  1. Install latest version:
    pip install -U apyrat
  2. Run:
    apyrat https://www.aparat.com/v/u75537l?playlist=289610
  3. Choose quality (e.g. 720p)

Expected behavior

The video should download successfully with the correct Persian filename.

Actual behavior

لینوکس از کیلومتر صفر (ویدیوی دوم: انتخاب توزیع گنو/لینوکس)
https://as9.cdn.asset.aparat.com/...
Traceback (most recent call last):
  ...
  File "/.../wget.py", line 506, in download
    (fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=prefix, dir=".")
  ...
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/apyrat/entekhab/لینوکس از کیلومتر صفر (ویدیوی دوم: انتخاب توزیع گنو/لینوکس).mp4xcjpfmtx.tmp'

Environment

  • OS: Debian 13 (also likely affects other Linux distributions)
  • Python: 3.11
  • apyrat version: latest (as of June 2026)
  • Shell: bash
  • Locale: UTF-8 (Persian)

Additional context

  • The bug occurs because wget.download() creates a temporary file using the full output filename (which contains Persian characters) as a prefix in tempfile.mkstemp().
  • The combination of Persian directory + Persian filename breaks the temporary file creation on some systems.
  • yt-dlp downloads the same video without any issues.

Suggested fix by AI

In src/apyrat.py (around line 158):

  1. Sanitize the filename (remove/replace invalid characters for the filesystem).
  2. Use a safe ASCII temporary filename.
  3. Consider replacing the wget module with requests + proper streaming, or use tempfile.mkstemp(dir="/tmp") explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions