Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magic Python not working

I am newbie in python, and I am working on a project that need to detect the type of the file so I used magic library, However the code is not working and it is raising exception. The test code is:

import magic
magic.from_file("./example.db")

The Traceback :

 Traceback (most recent call last):
- File "C:\Users\mariam\Desktop\pythonscripto\test.py", line 4, in <module>
    magic.from_file("./example.db")
- File "C:\Users\mariam\Desktop\pythonscripto\magic.py", line 122, in from_file
    m = _get_magic_type(mime)
- File "C:\Users\mariam\Desktop\pythonscripto\magic.py", line 111, in _get_magic_type
    i = _instances[mime] = Magic(mime=mime)
- File "C:\Users\mariam\Desktop\pythonscripto\magic.py", line 60, in \__init__
    magic_load(self.cookie, magic_file)
- File "C:\Users\mariam\Desktop\pythonscripto\magic.py", line 250, in magic_load
    return _magic_load(cookie, coerce_filename(filename))
- File "C:\Users\mariam\Desktop\pythonscripto\magic.py", line 181, in errorcheck_negative_one
    raise MagicException(err)
magic.MagicException: None

Any help?

like image 325
Ahmad Issa Avatar asked May 06 '26 03:05

Ahmad Issa


1 Answers

I solved this problem, only make sure that your Python version is 64 bit, as well as dependencies files, you should include the following files in the same folder:

  • regex2.dll
  • zlib1.dll
  • magic (no extension)
  • magic.mgc
  • libgnurx-0.dll
  • magic.py
like image 159
Ahmad Issa Avatar answered May 09 '26 01:05

Ahmad Issa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!