python-magic

logwatch使用

谁说胖子不能爱 提交于 2020-04-29 20:04:53
logwatch是一款用 Perl 语言编写的开源日志解析分析器。它能对原始的日志文件进行解析并转换成结构化格式的文档,也能根据您的使用情况和需求来定制报告。logwatch 的主要目的是生成更易于使用的日志摘要,并不是用来对日志进行实时的处理和监控的。正因为如此,logwatch 通常被设定好时间和频率的自动定时任务来调度运行或者是有需要日志处理的时候从命令行里手动运行。一旦日志报告生成,logwatch 可以通过电子邮件把这报告发送给您,您可以把它保存成文件或者直接显示在屏幕上。 安装: yum install logwatch -y 配置文件:/usr/share/logwatch/default.conf/logwatch.conf 我目前不想让它每天都执行,所以就删掉了/etc/cron.daily/0logwatch文件 手动执行 logwatch ################### Logwatch 7.4.0 (03/01/11) #################### Processing Initiated: Wed Apr 29 18:18:37 2020 Date Range Processed: yesterday ( 2020-Apr-28 ) Period is day. Detail Level of Output: 0 Type of

Django: file field validation in model using python-magic

好久不见. 提交于 2020-01-04 02:15:30
问题 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 method is working. class mymodel(models.Model): myfile = models.FileField() def clean(): mime = magic.from_buffer(self.myfile.read(), mime=True) print mime if not mime == 'application/pdf': raise ValidationError('File must be a PDF document') class

Python Error : File 5.3 supports only version 7 magic file

十年热恋 提交于 2019-12-25 04:19:09
问题 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 that gave me another error : File 5.3 supports only version 7 magic file. "magic.mgc" is version 12. Can I get a magic file version 7 ? 回答1: I searched a lot for a solution for this problem, but couldn't found. I was a little bit playing with

Python-Magic ; Unable to find libmagic [duplicate]

扶醉桌前 提交于 2019-12-25 03:55:10
问题 This question already has answers here : Python-magic installation error - ImportError: failed to find libmagic (3 answers) Closed 5 years ago . 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 cygwin installation into C:\Windows\System32. Then, I also downloaded magic1.dll and placed it in System32

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

前提是你 提交于 2019-12-24 21:15:37
问题 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 Windows 10. Here is the picture of the error: 回答1: This issue was discussed in GitHub: https://github.com/ahupp/python-magic/issues/154 It seems that solution is to reinstall libmagic "pip install libmagic" and/or "pip install python-magic" (the

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

可紊 提交于 2019-12-07 04:45:09
问题 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 python-magic and would like to check file types as follows per the specs for python-magic: mime = magic.Magic(mime=True) file_mime_type = mime.from_file('address/of/file.txt') However, recently uploaded files lack addresses on my server. I also do

How to use python-magic 5.19-1

懵懂的女人 提交于 2019-12-04 23:50:45
问题 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 happens is this: >>> import magic >>> magic.from_file("testdata/test.pdf") Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'from_file' So I had a look at the object, which provides

How to use python-magic 5.19-1

萝らか妹 提交于 2019-12-03 15:27:15
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 happens is this: >>> import magic >>> magic.from_file("testdata/test.pdf") Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'from_file' So I had a look at the object, which provides me with the class Magic for which I found documentation here: http://filemagic.readthedocs.org/en

Missing files for `magic` library on Windows

霸气de小男生 提交于 2019-11-29 14:39:48
问题 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 a folder and added the folder to my system PATH . Now when i execute magic methods, i get missing file exception: import magic print(magic.Magic()) Traceback (most recent call last): File "C:/Users/Admin/PycharmProjects/lex/lex.py", line 367, in

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

风格不统一 提交于 2019-11-29 07:33:20
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 your installation I have magic1.dll (along with the two other files the docs specified) in C:\Windows\System32 so I am not sure what the issue is. I would appreciate any help or workarounds. Go here and download the file "python_magic_bin-0.4.14-py2.py3-none-win32.whl", then pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl now python-magic