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
0
votes
1 answer

Python Error : File 5.3 supports only version 7 magic file

I installed python-magic with magic1.dll, regex2.dll, and zlib1.dll files and it imports correctly but when I try to do for example m = magic.Magic() I get the error : Could not find any magic file.So, I googled a little bit and found an answer here…
Zeiad Badawy
  • 51
  • 1
  • 10
0
votes
0 answers

PIP says python-magic is installed, but substanced says it is not

I'm followin the Substanced installation instructions here http://docs.pylonsproject.org/projects/substanced/en/latest/install.html step:3 $ bin/python -c "from substanced.file import magic; assert magic is not None, 'python-magic not installed'" =>…
Edmund Sulzanok
  • 1,883
  • 3
  • 20
  • 39
0
votes
2 answers

Differentiating between compressed .gz files and archived tar.gz files properly?

What is the proper way to deal with differentiating between a plain compressed file in gzip or bzip2 format (eg. .gz) and a tarball compressed with gzip or bzip2 (eg. .tar.gz) Identification using suffix extensions is not a reliable option as it's…
dcmbrown
  • 1,049
  • 9
  • 15
0
votes
1 answer

Validate a file before Uploading using python magic

I am using python magic to validate a file before uploading so for that I am following the below link: https://djangosnippets.org/snippets/3039/ validators.py file: from django.core.exceptions import ValidationError import magic class…
Sneha Shinde
  • 343
  • 7
  • 18
0
votes
1 answer

Find the file-type behind a file-handler in python

I am facing the problem to find out which is the file-type behind a file-handler. I need this because my apache_log_parser failed to parse a line and the whole program bumped out: Traceback (most recent call last): File…
Zioalex
  • 3,441
  • 2
  • 33
  • 30
0
votes
2 answers

Python-Magic ; Unable to find libmagic

I've downloaded and installed python-magic using "pip install python-magic". Source: https://github.com/ahupp/python-magic It downloaded and installed perfectly fine. I've also copied the 3 files (cygmagic-1.dll, cygwin1.dll, and cygz.dll) from…
Ida Lim
  • 95
  • 3
  • 11
0
votes
2 answers

error message using python magic on Windows XP

I followed the instructions here... https://github.com/ahupp/python-magic#dependencies I ran pip install python-magic and it installed without any issues. Then I installed cygwin and added C:\cygwin\bin to my system path. When I run the python…
b10hazard
  • 7,399
  • 11
  • 40
  • 53
0
votes
2 answers

How to reliable tell the uploaded file type (text or binary)?

I have an application where users should be able to upload a wide variety of files, but I need to know for each file, if I can safely display its textual representation as plain text. Using python-magic like m =…
moschlar
  • 1,286
  • 11
  • 18
-1
votes
2 answers

Python: OSError: [Errno 22] Invalid argument: '*.txt'

I have a script that I want to use in order to enumerate all file types in a folder: #!/usr/bin/env python # -*- coding: utf-8 -*- import sys import argparse import magic import os # Argparse starts here parser = argparse.ArgumentParser() …
-1
votes
2 answers

Executing a python script from scala giving error while running the same script from the command line does NOT

This is my python script: !/usr/bin/python import sys import magic m=magic.from_file('') print(m) On running this from the command line: $ python script.py Microsoft Word 2007+ results in the output…
Kireet Bhat
  • 77
  • 1
  • 2
  • 11
-1
votes
1 answer

Get MP3 MIME type using python

I am writing a script to determine if a file is a valid MP3 using python-magic. With some files, the magic.from_file() function returns use count (30) exceeded. Is it possible to raise the limit similar to the command line program: file --parameter…
mrtasktat
  • 323
  • 1
  • 4
  • 12
1 2 3
4