ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

MagicException : File 5.39 supports only version 16 magic file, magic.mgc is version 14 #269

Closed narayanan-ka closed 1 year ago

narayanan-ka commented 2 years ago

I'm getting this error of Magic version on my Virtual Environment when I run python3.8 manage.py migrate on my Django REST API.

I've already done the following after activating Virtual Environment:

pip3 install python-magic --upgrade Here is what exactly is shown at the very end.

magic.MagicException: b"File 5.39 supports only version 16 magic files.`myproject/misc/magic.mgc' is version 14>

Here is the detailed error log.

myproject_common/misc/magic.mgc, 2607: Warning: offset [' invalid myproject_common/misc/magic.mgc, 2608: Warning: offset[' invalid myproject_common/misc/magic.mgc, 2617: Warning: offset .' invalid myproject_common/misc/magic.mgc, 2619: Warning: offset.' invalid myproject_common/misc/magic.mgc, 2635: Warning: offset ' invalid myproject_common/misc/magic.mgc, 2653: Warning: offset.' invalid Traceback (most recent call last): File "manage.py", line 22, in execute_from_command_line(sys.argv) File "/home/earthling/myEnv/lib/python3.8/site-packages/django/core/management/init.py", line 381, in execute_from_command_line utility.execute() File "/home/earthling/myEnv/lib/python3.8/site-packages/django/core/management/init.py", line 357, in execute django.setup() File "/home/earthling/myEnv/lib/python3.8/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/home/earthling/myEnv/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/home/earthling/myEnv/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 843, in exec_module File "", line 219, in _call_with_frames_removed File "/home/earthling/myprojects/MyAPI/myproject_auth/models.py", line 31, in from myproject_common.utils.helpers import delete_file_field File "/home/earthling/myprojects/MyAPI/myproject_common/utils/helpers.py", line 131, in magic = magic.Magic(magic_file='myproject_common/misc/magic.mgc', mime=True) File "/home/earthling/myEnv/lib/python3.8/site-packages/magic.py", line 66, in init magic_load(self.cookie, magic_file) File "/home/earthling/myEnv/lib/python3.8/site-packages/magic.py", line 291, in magic_load return _magic_load(cookie, coerce_filename(filename)) File "/home/earthling/myEnv/lib/python3.8/site-packages/magic.py", line 217, in errorcheck_negative_one raise MagicException(err) magic.MagicException: b"File 5.41 supports only version 16 magic files. `myproject_common/misc/magic.mgc' is version 14"

ahupp commented 2 years ago

This error comes from the underlying libmagic rather than python-magic. It looks like there's a mismatch between your magic definitions file (the magic.mgc mentioned in the errors) and the version of libmagic installed in the container. If you do need your own copy of magic.mgc (why?), you'll need to downgrade libmagic. Alternatively, get rid of your copy of magic.mgc and use the distro-provided version.

narayanan-ka commented 2 years ago

Thanks for the assist. I'll do ghe above and come back with results

narayanan-ka commented 2 years ago

Hello. I deleted the magic.mgc in the project folder (5484 kb) and replaced it with the one in the Ubuntu root folder(7080 kb). Hope I'm it right ? Is there anything else i need to do ?

ahupp commented 2 years ago

If you change this line:

magic.Magic(magic_file='myproject_common/misc/magic.mgc', mime=True)

To remove the magic_file argument:

magic.Magic(mime=True)

It should Just Work, using the mgc file provided by the distro. With the added benefit that you don't run into this problem again next time it upgrades.

narayanan-ka commented 2 years ago

Hello. The error isn;'t there but the following error has appeared django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1:3307' (111)")

Is it related to Magic ?

ahupp commented 2 years ago

That's not related to libmagic or python-magic

On Sun, May 29, 2022, 8:50 PM Narayanan @.***> wrote:

Hello. The error isn;'t there but the following error has appeared django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1:3307' (111)")

Is it related to Magic ?

— Reply to this email directly, view it on GitHub https://github.com/ahupp/python-magic/issues/269#issuecomment-1140662011, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAJ5EWL3FIPBJDRP3UBMT3VMQ3GRANCNFSM5XGCMSEQ . You are receiving this because you commented.Message ID: @.***>

ahupp commented 1 year ago

This is a local libmagic install issue, closing.