Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Downloaded file names keep the URL query string, invalid on Windows

未關閉 適合新手
#1,336 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend

研究方向

閱讀 climada/util/files_handler.py 第 81 行附近和 climada/util/api_client.py 第 567 行附近,issue 在此指出了根據 URL 擷取檔名的問題。檢查這些下載路徑現有的測試,並補上包含查詢字串的 URL 測試。完成標準是兩個路徑都能產生不含查詢字串的本機檔名,而且在 Windows 上重現時不再引發無效檔名錯誤。

由索引模型根據 Issue 內容生成。

描述

bug

Describe the bug

download_file derives the local filename from the URL using url.split("/")[-1], which keeps the query string (climada/util/files_handler.py:81). The configured distance-to-coast URL ends in ?download=1, so the filename becomes GMT_intermediate_coast_distance_01d.zip?download=1. Since ? is not a valid character in Windows filenames, Centroids.get_dist_coast raises OSError: [Errno 22].

The same pattern is at climada/util/api_client.py:567.

To Reproduce

Steps to reproduce the behavior/error:

  1. On Windows, with no GMT_intermediate_coast_distance_01d.tif in ~/climada/data
  2. Run the code below

Code example:

from climada.util.coordinates import dist_to_coast_nasa
dist_to_coast_nasa([46.0], [8.0])
# OSError: [Errno 22] Invalid argument:
#   '...\\climada\\data\\GMT_intermediate_coast_distance_01d.zip?download=1'

Expected behavior

The query string is not part of the file name. Proposed fix at both sites:

from pathlib import PurePosixPath
from urllib.parse import urlsplit

file_name = PurePosixPath(urlsplit(url).path).name
# api_client.py: path /= unquote(PurePosixPath(urlsplit(url).path).name)

Happy to open a PR.

Screenshots

n/a

Climada Version: 6.1.1-dev (develop)

System Information (please complete the following information):

  • Operating system and version: Windows 11 (10.0.26200)
  • Python version: 3.12.13

Additional context

n/a

主要語言
Jupyter Notebook
星號
478
分支
166
平均合併
1 天 20 小時
30 天內合併 PR
2

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CLIMADA-project/climada_python 的其他 Issue

查看 CLIMADA-project/climada_python 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。