。py文件中此代码的第一行返回错误。
mime = magic.Magic(mime=True)
content_type = mime.from_buffer((data).read(1024))
request.session['content_type'] = content_type
if content_type == 'application/pdf' or content_type == 'application/msword':
request.session['upload_status'] = "Content type is valid according to (MAGIC)"
错误消息是__init__() got an unexpected keyword argument 'mime'
我正在使用Django 1.4.1和Python 2.7.3。我已经安装了魔术。不知道出了什么问题,不胜感激!
import magic
magic.from_buffer(open("testdata/test.pdf").read(1024))
The error message is __init__() got an unexpected keyword argument 'mime'
然后编辑
/usr/lib/python2.7/site-packages/jira/client.py
替换
self._magic = magic.Magic(mime=True)
与
self._magic = magic
然后运行如下代码:
from jira.client import JIRA
import magic
...
jira = JIRA(options={'server':'https://jira.server.goes.here'}, basic_auth=(options.username, options.password))
我正在将python 2.7.3与jira-python(http://jira-python.readthedocs.org/en/latest/)一起使用
$ sudo pip3 uninstall filemagic
$ sudo pip3 install python-magic
或者,什么在我的Cygwin安装中更有效:
$ python -m pip uninstall filemagic
$ python -m pip install python-magic
这为我解决了问题。
当我搜索有关此问题的更多信息时,我在github上遇到了非常相似的解决方案here(archived)。还有一个额外的步骤。卸载filemagic:
sudo pip3 uninstall filemagic
卸载python-magic:
sudo pip3 uninstall python-magic
安装python-magic:
sudo pip3 install python-magic
通过快速搜索,我找不到
magic
的两个版本的详细信息。我刚刚在线程上发现一些注释,说“您必须具有magic
的其他版本”或“您必须具有magic
的其他版本”。