Why do some files not have mimetypes?
guess_type
returns a tuple with information about the file type
like 'image/jpeg'
, 'application/xml'
, 'text/plain'
, ....
Why do other files return no information 'None'
even though the file exits and is not empty?
>> import mimetypes
>> mimetypes.guess_type('myfile.xx')
(Answered here: How to find the mime type of a file in python?)
Do this:
>>> pip install python-magic
>>> import magic
>>> mime = magic.Magic(mime=True)
>>> mime.from_file("testdata/test.pdf")
The "mimetypes" library isn't very good, (it's unreliable). The "none" is that the specified file isn't recognized as a known filetype, (an extension don't a fileype make).
Hope this solves your issue and answers your question