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
1
vote
1 answer

Why is magic.from_buffer returning None?

Here's what I get when I call magic.from_buffer: >>> import urllib2 >>> data = urllib2.urlopen('http://www.in.gov/judiciary/opinions/previous/wpd/05040501.bed.doc').read() >>> len(data) 29696 >>> from lib import magic >>> magic.from_buffer(data,…
mlissner
  • 17,359
  • 18
  • 106
  • 169
0
votes
0 answers

Module function magic.from_file returns different result in Windows and Centos

The from_file in python package python-magic returns different results for the same file in Windows vs Centos. For e.g on Windows, from magic import from_file print(from_file("path\to\file_name.msi", mime=True)) # Below is the…
0
votes
0 answers

Exception Value:failed to find libmagic. Check your installation in windows 11?

(https://i.stack.imgur.com/vlQMv.png) Error during the libmagic installation When i am doing lanchain + gpt + python project using jupyter notebook its always shows this error. I installed libmagic and I also installed python magic. I have done pipi…
0
votes
1 answer

use two libraries with same modules in python

Two libraries are found on Pypi, 'python-magic' and 'filemagic', which can be imported with same import statement: https://pypi.org/project/python-magic/ https://pypi.org/project/filemagic/ import magic I want to import both of these libraries in my…
0
votes
0 answers

How I can compare two folders with multi-volume .7Z archive files, and get the output files/folders where the difference is more than 1GB

I have 2 paths where each one them has multi-volume .7Z archive files. Path A contains 4 files: example1.7z.001, example1.7z.002, example1.7z.003, example1.7z.004 (Total size of all is 15 GB). Once you extract you get one 7z file of 20GB, and once…
arielma
  • 1,308
  • 1
  • 11
  • 29
0
votes
0 answers

Python-magic not recognized while trying to import in Django

I am trying to check the file type of the uploaded data using magic but pylance is not recognizing it I keep getting this error pylance error I installed python-magic 0.4.27 My python version is- 3.9 Django-version- 4.1.3 I tried adding python-magic…
Mercy
  • 3
  • 3
0
votes
1 answer

What happens exactly when a python class instance use dot to access attributes?

Suppose a class A is defined as: class A: def __init__(self, val): self.val = val After A is instantiated by a = A(3), what methods will be called by executing a.val? In other words, what will happen internally when a.val is…
0
votes
0 answers

Getting correct MIME type of a json file containing empty arrays

Using python-magic, I'm trying to guess the mime type of simple files and stumble upon this: if the json contains an empty array, the mime type returned is 'text/plain' instead of 'application/json'. First, import magic and from pathlib import Path,…
zezollo
  • 4,606
  • 5
  • 28
  • 59
0
votes
0 answers

Python Docker Image ImportError: python-magic

Trying to create a very basic python image with a Dockerfile: FROM python:3.8-slim RUN pip3 install python-magic The build works fine but when I try to run the container and simply import magic, python gives: Traceback (most recent call…
Frankster
  • 653
  • 7
  • 26
0
votes
1 answer

python-magic on GCP App Engine - failing to deploy

I am working on Python app that will be deployed to GCP App Engine. I tried to use python-magic functionality. I've added import magic to my code and python-magic to the requirements.txt file. But when I try to deploy code to App Engine it fails…
Michał Herman
  • 3,437
  • 6
  • 29
  • 43
0
votes
1 answer

'magic.h' file not found?

Attempting to use the Panoptes client package and installed libmagic & magic after panoptes required. After configuring, I finally tried to run the command to upload my images: panoptes subject-set upload-subjects -m image/jpeg 28014…
morais12
  • 33
  • 1
  • 6
0
votes
1 answer

Does python-magic package works to check mime-type of video file of format .mp4?

I am trying to use python-magic package to identify the uploaded file type(using mime-type), I have used it to identify image and audio file it works fine but for the video file, it throws an error. For video file I have class…
Bhoj
  • 41
  • 10
0
votes
1 answer

fatal error C1083: Cannot open include file: 'magic.h': No such file or directory

trying to run a django server on my windows 10 computer. When I execute python manage.py runserver, I get the following error: fatal error C1083: Cannot open include file: 'magic.h': No such file or directory I'm running 64 bit python 3.5, on…
Shaun Chua
  • 705
  • 3
  • 13
  • 32
0
votes
1 answer

Problems importing magic on Windows 64-bit

I have searched on the internet for a solution to import magic correctly in Windows 10 64-bit. I found this, but I do not understand the solution. It says to copy two DLLs into the specified path in the OS. What does the below command mean?…
Sabari
  • 1
  • 2
0
votes
0 answers

Python Magic not working with Django on Digitalocean server

I've recently been deploying a Django project on a digital ocean server (ubuntu). I'm using Nginx and securing the connection with lets encrypt. Here's my problem: I was able to use python magic to validate uploads (during development), but it…
Adam Yui
  • 139
  • 11