Questions tagged [python-magic]

python-magic is a python interface to the libmagic file type identification library.

python-magic is a python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers according to a predefined list of file types. This functionality is exposed to the command line by the Unix command file.

See https://github.com/ahupp/python-magic

56 questions
12
votes
2 answers

python-magic installation challenges for 64-bit Windows 10 running 32-bit Python 2.7 build

Despite following the readme for the module, I continue to get "magic files not found". The readme and "Dependencies" section say: On Windows, copy magic1.dll, regex2.dll, and zlib1.dll onto your PATH from the Binaries and Dependencies zip files…
Suzanne
  • 582
  • 2
  • 11
  • 31
10
votes
5 answers

Python-magic installation error - ImportError: failed to find libmagic

I am trying to install python-magic for Windows and I have followed all the instructions in https://github.com/ahupp/python-magic and repeated the process several times but I am still getting this error: ImportError: failed to find libmagic. Check…
wlingke
  • 4,699
  • 4
  • 36
  • 52
10
votes
5 answers

Missing files for `magic` library on Windows

I need to get mime type for some files on windows, so i've installed python-magic (on 32-bit python 2.7.3). It depends on unix magic library. Author instructs to get regex2.dll, zlib1.dll and magic1.dll from gnuwin32 project. So i saved the files to…
user2052437
  • 173
  • 1
  • 1
  • 8
8
votes
1 answer

Import Error: No module called magic yet python-magic is installed

I am trying to edit some code that uses python-magic but I get an Import Error: No module called magic. Before I looked around the Internet and found advise on installing python-magic using pip which I did. I installed python-magic using pip…
Joannah Nanjekye
  • 429
  • 1
  • 5
  • 16
8
votes
1 answer

How to use python-magic 5.19-1

I need to determine MIME-types from files without suffix in python3 and I thought of python-magic as a fitting solution therefor. Unfortunately it does not work as described here: https://github.com/ahupp/python-magic/blob/master/README.md What…
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50
6
votes
5 answers

How does one use magic to verify file type in a Django form clean method?

I have written an email form class in Django with a FileField. I want to check the uploaded file for its type via checking its mimetype. Subsequently, I want to limit file types to pdfs, word, and open office documents. To this end, I have installed…
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
4
votes
0 answers

Generic way to check the architecture of a file

Is there a general way to check the platform (32-bit/64-bit) and architecture (powerpc, arm, etc...) of a binary file (Which can be ELF, Dwarf, PE, etc...)? I know that almost every file (elf or pe) has a header which says which architecture can…
Drxxd
  • 1,860
  • 14
  • 34
3
votes
1 answer

Why python-magic returns wrong mime-type if file size is too small?

In case of the file size is under 5000 bytes (InMemoryUploadedFile). This code doesn't work mime_type = magic.from_buffer(file.read(), mime=True) It returns wrong mime_type. For example, I have a file cv.docx with 4074 bytes size. It returns a…
3
votes
0 answers

Python-Magic 'could not find any valid magic files!'

I want to use Python-Magic library, but I get: magic.magic.MagicException: b'could not find any valid magic files!' Error on a simple code like this: filepath = 'path\\somefile.txt' print(magic.from_file(filepath)) I did google the error message…
MertTheGreat
  • 500
  • 1
  • 7
  • 20
3
votes
2 answers

Django: file field validation in model using python-magic

I have a model containing file field. I want to restrict it to pdf files. I have written clean method in model because I want to check for admin and shell level model creation also. But it is not working in model clean method. However form clean…
2
votes
1 answer

How can I find the mimetype of a file without extension that is sent to me inside a zip file?

I have a simple problem: in a system I'm developing the user can send us zipfiles and I need to filter the content of it. (block applications and malicious scripts) To block the inner files by extension is easy, but files without extension are very…
Jayme Tosi Neto
  • 1,189
  • 2
  • 19
  • 41
2
votes
1 answer

Determine image in memory

I want to determine if a buffer I have (downloaded it) is an image file, without saving it to the disk. I looked it up and found out that: imghdr can do it only for files. python-magic can give me the file type, but than I need to map it to image…
2
votes
3 answers

python-magic WindowsError: [Error 193] %1 is not a valid Win32 application

Hi I'm trying to use python-magic on windows 8 but when I try to import with the command import magic it gives me this error WindowsError: [Error 193] %1 is not a valid Win32 application I have tried both with 64-bit and 32-bit version of Python…
Lorenzo Bottaccioli
  • 441
  • 1
  • 7
  • 20
2
votes
1 answer

parse python functions as a string within decorator

I am trying to write a function debug decorator that will look at: def foo(baz): bar = 1 bar = 2 return bar and wrap it to: def foo(baz): bar = 1 print 'bar: {}'.format(bar) bar = 2 print 'bar: {}'.format(bar) return bar I need to…
codyc4321
  • 9,014
  • 22
  • 92
  • 165
2
votes
1 answer

python-magic WindowsError: access violation writing 0x00000000

I installed python-magic (0.4.6) on my Win 7 64bit using pip. I then installed cygwin 1.7.33-2 to provide the needed dlls and created a copy of cygmagic-1.dll named magic1.dll (see When I run the Python 2.7.6 32bit shell, the "import magic" works…
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
1
2 3 4