[Django]-__init__() got an unexpected keyword argument 'mime' in python/django

4👍

Just a stab in the dark but The documentation would suggest that you shouldn’t be instantiating the Magic class directly.

import magic
magic.from_buffer(open("testdata/test.pdf").read(1024))

1👍

The Magic object’s constructor does not accept an argument named ‘mime’. I would suggest looking at the doc string with help(magic.Magic); it may give you a clue.

1👍

As per suggestions above, if connection to JIRA server fails with error:

The error message is __init__() got an unexpected keyword argument 'mime'

Then go edit

/usr/lib/python2.7/site-packages/jira/client.py 

Replace

self._magic = magic.Magic(mime=True)

with

self._magic = magic

Then run code like this:

from jira.client import JIRA
import magic
...
jira = JIRA(options={'server':'https://jira.server.goes.here'}, basic_auth=(options.username, options.password))

I’m using python 2.7.3 with jira-python (http://jira-python.readthedocs.org/en/latest/)

1👍

You most likely have another version of magic. If I remember correctly from the last time I looked this stuff up, there’s a different version that comes with Ubuntu (maybe, there’s also something called filemagic). The same thing is the case on the out-of-the-box version of Cygwin. That was my case.

I had reinstalled Cygwin and ran into this same issue – two versions of magic / python-magic / filemagic for Python. I looked back here on SO for the solution, but didn’t find it quickly. Luckily, I kept notes from before, and the solution that worked for me was:

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

OR, what worked better on my Cygwin installation:

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

That fixed the problem for me.

As I searched for more on this problem, I came across a very similar solution here (archived), on github. There is an additional step.

uninstall filemagic:

sudo pip3 uninstall filemagic

uninstall python-magic:

sudo pip3 uninstall python-magic

(Possible addition)

sudo apt-get uninstall python-magic

install python-magic:

sudo pip3 install python-magic

With a quick search, I couldn’t find details of the two versions of magic. I just found some comments on threads saying, "You must have the other version of magic", or "You must have a different version of magic".

Edit
I’ve updated this answer with the magic sources. From this, it seems that you might have to do another command before installing python-magic with pip

sudo apt-get uninstall python-magic

as noted above.


Edit

I found the details about the different versions of magic that are floating around.

I have the following three links ( first , second , third )

Basically, there are two versions going around. The one which has the most support is on PYPI and (it seems to me) is used much more often. It is v.0.4.15 currently (2020-02-19), and its github page is the first link. At that page, you can read the following:

Name Conflict

There are, sadly, two libraries which use the module name magic. Both have been around for quite a while. If you are using this module and get an error using a method like open, your code is expecting the other one. Hopefully one day these will be reconciled.

The second version, which seems to cause the most problems, is currently (2020-02-19) v5.25. According to the third link and my own research, this one gets installed when one uses sudo apt-get install python-magic on certain versions of Ubuntu. (Look here for some possible details from Ubuntu.)

The best explanation of all this is found in the second link. Props to @mhawke for explaining things so well.

Here are archived versions of the links above: archived first, archived second, archived third, archived Ubuntu information.

Leave a comment