[issue30268] Make mimetypes.guess_type accept path-like objects

ProgVal report at bugs.python.org
Thu May 4 12:08:06 EDT 2017


New submission from ProgVal:

The documentation for mimetypes.guess_type says that it “guesses the type of a file based on its filename or URL”.

However, this function only accepts a string object, and not a bytes object:

>>> import os
>>> import mimetypes
>>> mimetypes.guess_type(os.listdir(os.fsencode('./'))[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/mimetypes.py", line 291, in guess_type
    return _db.guess_type(url, strict)
  File "/usr/lib/python3.7/mimetypes.py", line 116, in guess_type
    scheme, url = urllib.parse.splittype(url)
  File "/usr/lib/python3.7/urllib/parse.py", line 924, in splittype
    match = _typeprog.match(url)
TypeError: cannot use a string pattern on a bytes-like object

----------
components: Library (Lib)
messages: 292995
nosy: Valentin.Lorentz
priority: normal
severity: normal
status: open
title: Make mimetypes.guess_type accept path-like objects

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30268>
_______________________________________


More information about the Python-bugs-list mailing list