Downloaded file names keep the URL query string, invalid on Windows
還沒有人認領這個 Issue。
評估
研究方向
閱讀 climada/util/files_handler.py 第 81 行附近和 climada/util/api_client.py 第 567 行附近,issue 在此指出了根據 URL 擷取檔名的問題。檢查這些下載路徑現有的測試,並補上包含查詢字串的 URL 測試。完成標準是兩個路徑都能產生不含查詢字串的本機檔名,而且在 Windows 上重現時不再引發無效檔名錯誤。
由索引模型根據 Issue 內容生成。
描述
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:
- On Windows, with no
GMT_intermediate_coast_distance_01d.tifin~/climada/data - 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
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
CLIMADA-project/climada_python 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
CLIMADA-project/climada_python#1337 ·
-
CartoDB basemaps now need an API key (somewhat urgent)可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
CLIMADA-project/climada_python#1332 · 4 則留言 · 1 個 reaction ·
-
warnings
難度 2/5 1-3 小時 新手友好度 65/100
CLIMADA-project/climada_python#1241 ·
-
ResourceWarning未關閉warnings
難度 2/5 1-3 小時 新手友好度 62/100
CLIMADA-project/climada_python#1239 ·
-
warnings
難度 2/5 1-3 小時 新手友好度 62/100
CLIMADA-project/climada_python#1226 ·
查看 CLIMADA-project/climada_python 的全部 Issue
相似的 Issue
-
0.2.1-rc.3 compatibility: 21 peer ranges enumerate exact versions, so rc.3 is rejected可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
NanmiCoder/dsh-agent-teams#277 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 85/100
-
難度 2/5 1-3 小時 新手友好度 87/100
Lakr233/vphone-cli#742 ·
維護者通常 1 天內回覆
-
[core-client] Remove unused hand-maintained transport helpers after the definition-table cutover未關閉doc-audit enhancement
難度 2/5 1-3 小時 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆