Skip to content

Unable to download file with improper name #3

@vzahradnik

Description

@vzahradnik

This app automatically tries to name the downloaded files. The problem is if the original name contains invalid characters, for example "Week 2: Abc Def"

In Windows, this results in an error:

NotADirectoryError: [WinError 267] The directory name is invalid: 'Week 2: Intent and Premise'
(venv) PS C:\Users\vladi\Downloads\sprout_downloader_python> python .\sprout.py --help
C:\Users\vladi\Downloads\sprout_downloader_python\venv\Lib\site-packages\requests\__init__.py:89: RequestsDependencyWarning: urllib3 (2.3.0) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "

Note: The error above is from the Python version of this script. It was easier to debug.

I fixed the issue temporarily like this:

# Remove the double quotes in the title name
title = data.get('title').replace('"', '')

# Remove (or replace) any invalid Windows filename characters
# This example replaces them with an underscore
title = re.sub(r'[<>:"/\\|?*]', '_', title)

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