Skip to content

getCacheDirectoryForDownloads throws exception when encountering unicode paths #21960

@liuxingbaoyu

Description

@liuxingbaoyu
System information (version)
  • OpenCV => 4.2
  • Operating System / Platform => Windows 11
  • Compiler => Visual Studio 2019
Detailed description

getCacheDirectoryForDownloads uses GetTempPathA on Windows.

It uses the environment variable TMP.

Default: C:\Users\username\AppData\Local\Temp

getCacheDirectoryForDownloads throws an exception when the username contains unicode characters.

E.g: C:\Users\流星暴雨\AppData\Local\Temp

Steps to reproduce
# -*- coding: utf-8 -*-

import tempfile
import cv2

os.environ["TMP"] = tempfile.mkdtemp("测试")
print(cv2.utils.fs.getCacheDirectoryForDownloads())
PS F:\opencv_test> python .\1.py
Traceback (most recent call last):
  File "F:\opencv_test\1.py", line 10, in <module>
    print(cv2.utils.fs.getCacheDirectoryForDownloads())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 9: invalid start byte
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions