Skip to content

Commit

Permalink
Gracefully handle Windows registry access errors during mimetype dete…
Browse files Browse the repository at this point in the history
…ction (#13183)
  • Loading branch information
JoaStuart authored Feb 13, 2025
1 parent c5f3d69 commit 1a8c17a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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.
7 changes: 6 additions & 1 deletion src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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

0 comments on commit 1a8c17a

Please sign in to comment.