an example of suppress (#24136)
This commit is contained in:
parent
a2537ba4fd
commit
ebd2c8236d
1 changed files with 2 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import contextlib
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
|
@ -65,10 +66,8 @@ def guess_file_info_from_response(response: httpx.Response):
|
||||||
|
|
||||||
# Use python-magic to guess MIME type if still unknown or generic
|
# Use python-magic to guess MIME type if still unknown or generic
|
||||||
if mimetype == "application/octet-stream" and magic is not None:
|
if mimetype == "application/octet-stream" and magic is not None:
|
||||||
try:
|
with contextlib.suppress(magic.MagicException):
|
||||||
mimetype = magic.from_buffer(response.content[:1024], mime=True)
|
mimetype = magic.from_buffer(response.content[:1024], mime=True)
|
||||||
except magic.MagicException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
extension = os.path.splitext(filename)[1]
|
extension = os.path.splitext(filename)[1]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue