Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,336 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Đọc climada/util/files_handler.py quanh dòng 81 và climada/util/api_client.py quanh dòng 567, nơi issue chỉ ra việc trích xuất tên tệp dựa trên URL. Kiểm tra các bài kiểm tra hiện có cho những đường dẫn tải xuống này và bổ sung kiểm thử cho URL có chuỗi truy vấn. Công việc hoàn tất khi cả hai đường dẫn tạo ra tên tệp cục bộ không có chuỗi truy vấn và trường hợp tái hiện trên Windows không còn gây lỗi tên tệp không hợp lệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Jupyter Notebook
Star
478
Fork
166
Merge trung bình
2 ngày 31 phút
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CLIMADA-project/climada_python

Tất cả issue của CLIMADA-project/climada_python

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.