Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 12769 mimetypes windows error #13183

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/12769.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gracefully handle Windows registry access errors while guessing the MIME type of a file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for other reviewers, while the code comment is more general because it seems guess_type() can fail on any platform (according to the docs), the only reports in practice are on Windows w/ the registry.

7 changes: 6 additions & 1 deletion src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ class File:

def __post_init__(self) -> None:
if self.content_type is None:
self.content_type = mimetypes.guess_type(self.path)[0]
# Try to guess the file's MIME type. If the system MIME tables
# can't be loaded, give up.
try:
self.content_type = mimetypes.guess_type(self.path)[0]
except OSError:
pass


def get_http_url(
Expand Down
Loading