ATH-MaaS/Pixelle-Video · error · FileNotFoundError

文件不存在: {file_path}

Error message

文件不存在: {file_path}

What it means

upload verifies the file exists on disk before starting the upload workflow (policy fetch → OSS upload → registration) and raises FileNotFoundError when os.path.exists(file_path) is false. Failing fast avoids wasted API calls for a nonexistent local file.

Source

Thrown at pixelle_video/services/api_services/image_processor.py:370

    
    def upload(self, file_path: str) -> str:
        """
        上传文件到阿里云OSS并获取URL(统一接口方法)
        
        Args:
            file_path: 本地文件路径
            
        Returns:
            oss_url: OSS URL,可在48小时内使用
            
        Raises:
            FileNotFoundError: 文件不存在时
            RuntimeError: API Key未设置时
            Exception: 上传失败时
        """
        # 检查文件是否存在
        if not os.path.exists(file_path):
            raise FileNotFoundError(f"文件不存在: {file_path}")
        
        if not self.api_key:
            raise RuntimeError("DASHSCOPE_API_KEY 未设置,无法使用图片上传服务")
        
        # 1. 获取上传凭证(注意:上传凭证接口有限流)
        policy_data = self.get_upload_policy()
        
        # 2. 上传文件到OSS
        oss_url = self.upload_file_to_oss(policy_data, file_path)
        
        # 3. 计算过期时间
        expire_time = datetime.now() + timedelta(hours=48)
        
        logging.info(f"文件上传成功: {file_path}")
        logging.info(f"  OSS URL: {oss_url}")
        logging.info(f"  过期时间: {expire_time.strftime('%Y-%m-%d %H:%M:%S')} (48小时)")
        
        return oss_url

View on GitHub (pinned to 848b054e4f)

Solutions

  1. Verify the file path exists (os.path.exists) before calling upload; fix the path or regenerate the file.
  2. Use absolute paths (os.path.abspath) so a changing working directory cannot break resolution.
  3. Check that the earlier step that was supposed to produce the file (e.g. download_image) actually succeeded.
  4. Confirm the file was not moved/cleaned up by another process between creation and upload.

Example fix

// before
processor.upload(relative_path)  # depends on cwd

// after
path = os.path.abspath(relative_path)
if not os.path.exists(path):
    raise FileNotFoundError(f"Cannot upload, missing file: {path}")
processor.upload(path)
Defensive patterns

Strategy: validation

Validate before calling

import os
path = os.path.abspath(file_path)
if not os.path.exists(path):
    raise FileNotFoundError(f"File to upload does not exist: {path}")
if not os.path.isfile(path):
    raise ValueError(f"Path is not a file: {path}")

Type guard

def is_existing_file(path) -> bool:
    return isinstance(path, str) and os.path.isfile(path)

Try / catch

try:
    url = processor.upload(file_path)
except FileNotFoundError as e:
    logging.error(f"Upload aborted, file missing: {e}")
    # regenerate or re-download the file before retrying
    raise

Prevention

When it happens

Trigger: Calling upload with a path that does not exist: typo'd path, file deleted/moved by an earlier pipeline step, relative path resolved from a different working directory, or a previous download step failed silently.

Common situations: Working directory differs between save and upload (relative paths break), image download failed earlier but the pipeline continued with a stale path, path built with wrong separators or case on Linux.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of ATH-MaaS/Pixelle-Video@848b054e4f (2026-08-30). Data as JSON: /api/errors/e11d515a45c5bb95. Report an issue: GitHub.