__ init __()在python / django中获得了意外的关键字参数'mime'

问题描述 投票:3回答:4

。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。我已经安装了魔术。不知道出了什么问题,不胜感激!

python django mime magic-methods
4个回答
4
投票
import magic magic.from_buffer(open("testdata/test.pdf").read(1024))

1
投票

1
投票
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/)一起使用


0
投票
我重新安装了Cygwin,并遇到了同样的问题。我在SO上回头寻找解决方案,但是没有很快找到它。幸运的是,我以前记过笔记,对我有用的解决方案是:

$ sudo pip3 uninstall filemagic $ sudo pip3 install python-magic

或者,什么在我的Cygwin安装中更有效:

$ python -m pip uninstall filemagic
$ python -m pip install python-magic

这为我解决了问题。

当我搜索有关此问题的更多信息时,我在github上遇到了非常相似的解决方案herearchived)。还有一个额外的步骤。

卸载filemagic:

sudo pip3 uninstall filemagic

卸载python-magic:

sudo pip3 uninstall python-magic

安装python-magic:

sudo pip3 install python-magic

通过快速搜索,我找不到magic的两个版本的详细信息。我刚刚在线程上发现一些注释,说“您必须具有magic的其他版本”或“您必须具有magic的其他版本”。

© www.soinside.com 2019 - 2024. All rights reserved.