Closed gabn88 closed 3 years ago
If I do magic.from_file(filepath, mime=True) I get the correct MIMEtype, however if I first open the file:
with open(filepath) as file: magic.from_buffer(file.read(), mime=True)
I get:
File "/usr/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 10: invalid start byte.
This means I would have to open the file twice as I need it later on. Is there something I'm doing wrong or it is a bug?
I'm guessing you figured this out, but you'll want open(..., mode='b') here.
open(..., mode='b')
Thanks! I didn't find that answer, was struggling through the encoding documentation.
If I do magic.from_file(filepath, mime=True) I get the correct MIMEtype, however if I first open the file:
I get:
This means I would have to open the file twice as I need it later on. Is there something I'm doing wrong or it is a bug?