Skip to content

Commit 1a8c17a

Browse files
authored
Gracefully handle Windows registry access errors during mimetype detection (#13183)
1 parent c5f3d69 commit 1a8c17a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

news/12769.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Gracefully handle Windows registry access errors while guessing the MIME type of a file.

src/pip/_internal/operations/prepare.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ class File:
8787

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

9297

9398
def get_http_url(

0 commit comments

Comments
 (0)