ahupp / python-magic

A python wrapper for libmagic
Other
2.62k stars 282 forks source link

magic.MagicException: None #160

Closed francesco1119 closed 6 years ago

francesco1119 commented 6 years ago

I'm using your library for my Python3 script. It works very well on Windows 10 Linux bash but when I switch back to Windows 10 Command Prompt the same script is not working.

Traceback (most recent call last):
  File "Pukeko.py", line 159, in <module>
    dirlist(path)
  File "Pukeko.py", line 155, in dirlist
    dirlist(i)
  File "Pukeko.py", line 151, in dirlist
    LetsTry(i)
  File "Pukeko.py", line 127, in LetsTry
    elif "text" in magic.from_file(p, mime=True):
  File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 135, in from_file
  File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 123, in _get_magic_type
  File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 67, in __init__
  File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 264, in magic_load
  File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 195, in errorcheck_negative_one
magic.MagicException: None

I think this is mainly due to the fact that on Windows I'm using Miniconda.

evidence

Is there any workaround?

ahupp commented 6 years ago

This probably means it can't find the magic file that defines all the file types. Try passing it in explicitly to the constructor of magic.Magic.

On Tue, Feb 13, 2018 at 12:09 AM, Francesco Mantovani < notifications@github.com> wrote:

I'm using your library for my Python3 script. It works very well on Windows 10 Linux bash but when I switch back to Windows 10 Command Prompt the same script is not working.

Traceback (most recent call last): File "Pukeko.py", line 159, in dirlist(path) File "Pukeko.py", line 155, in dirlist dirlist(i) File "Pukeko.py", line 151, in dirlist LetsTry(i) File "Pukeko.py", line 127, in LetsTry elif "text" in magic.from_file(p, mime=True): File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 135, in from_file File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 123, in _get_magic_type File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 67, in init File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 264, in magic_load File "C:\Users\franc\Miniconda3\lib\site-packages\python_magic-0.4.15-py3.6.egg\magic.py", line 195, in errorcheck_negative_one magic.MagicException: None

I think this is mainly due to the fact that on Windows I'm using Miniconda.

[image: evidence] https://user-images.githubusercontent.com/3397477/36139384-2afd0422-1102-11e8-82be-ed4cf353f28c.PNG

Is there any workaround?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ahupp/python-magic/issues/160, or mute the thread https://github.com/notifications/unsubscribe-auth/AACekgiJQJYE0D71rZP-8Kp8p9K4APZLks5tUUNAgaJpZM4SDW4L .

-- Adam Hupp | http://hupp.org/adam/

polnikov commented 2 years ago

i have the same problem When I indicate explicitly: изображение i get correct output: изображение

but in Django project the same code: изображение изображение

it's just txt file

ahupp commented 2 years ago

@polnikov can you use procmon to look at what is being opened (both the magic DLL and the magic DB file) in those two examples? My guess is that one or both are different due to slightly different paths.