[Solved] Can't upload any file to library: [ERROR] 'module' object has no attribute 'open'

The system has been up and running for a long time without any problem, suddenly today I started having problems uploading files, mp3 or ogg. (I didn’t test other formats)
Airtime analyzer complains with:

2017-12-11 15:38:06,670 [analyzer_pipeline] [ERROR]  'module' object has no attribute 'open'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/airtime_analyzer-0.1-py2.7.egg/airtime_analyzer/analyzer_pipeline.py", line 70, in run_analysis
    metadata = MetadataAnalyzer.analyze(audio_file_path, metadata)
  File "/usr/local/lib/python2.7/dist-packages/airtime_analyzer-0.1-py2.7.egg/airtime_analyzer/metadata_analyzer.py", line 44, in analyze
    ms = magic.open(magic.MIME_TYPE)
AttributeError: 'module' object has no attribute 'open'
2017-12-11 15:38:06,679 [message_listener] [ERROR]  Analyzer pipeline exception: 'module' object has no attribute 'open'
2017-12-11 15:38:06,920 [status_reporter] [INFO ]  HTTP request sent successfully.

Weird. Off the top of my head, I’d search the github for term magic as I know we did some stuff with that.
I assume you didn’t change anything and it just started to not work. Did you do an system update or anything that might of triggered this ?

I figure you tried restarting analyzer ?

Ok so according to this commit - https://github.com/LibreTime/libretime/commit/9ce611130cef733251da72467314bffc5922ee15 we are not using python magic anymore and instead are using file magic.

A little googling found this as well - https://stackoverflow.com/questions/18226536/python-magic-module-object-has-no-attribute-open#18228897

So something happened, any idea if you might have done anything that could of caused this ?

No system update nor change since last successful uploads, it just stopped working, so weird

Hmm, make sure you have file.magic vs. python magic or possibly revert that code commit I linked too, because it should be using file.open only if you have file.magic. I’m not heavily versed in the python side of things but I can see this is what is causing it. Now what changed to make this happen is the bigger mystery.

Reverting to the old code and restarting airtime_analyzer does nothing, it does neither fire any exception, I could not install file-magic because I cannot find any package named file-magic.

Did you try to do it with pip
sudo pip install file-magic

It isn’t a system package.

sudo pip install file-magic
Requirement already satisfied: file-magic in /usr/local/lib/python2.7/dist-packages/file_magic-0.3.0-py2.7.egg

I did it! apparently there was a problem with debian’s package python-magic. This is what I did:

apt-get remove python-magic
sudo pip uninstall python-magic
sudo pip uninstall file-magic
sudo pip install file-magic
service airtime_analyzer restart

and now ms.open works, no need to use the old code!

Unrelated but you are using Debian and your able to import mp3 files correct ? I have a 9.2 install and all mp3 files file to import and liquidsoap gives segmentation faults. I’m trying to figure out what the cause is because I’m pretty sure some Debian installs are working for people.

Based upon github I’m presuming your using liquidsoap 1.3 self-installed.

I just installed a new instance of Libretime 3.0.0-alpha.3 on a Debian 9 server, I could not successfully start liquidsoap yet, but as soon as I can I will let you know if I can or not upload mp3 files.

I can confirm that I can upload mp3 as well as ogg files in my recently installed Debian server with Libretime alpa.3. I just had to install some missing liquidsoap plugins after running the installer and that was it… everything seems to work as expected.

The issue happened again and no changes were made to the system. Not intentional at least. At 17:22 people was uploading files without any problem. At 17:38 the problem started to happen and users were not able to upload more tracks. During the period no changes or updates to the system. I am supposed to be the only administrator with root access and did not any installation or update whatsoever. Actually I was not even connected to the server. Is there something that might be installing python-magic ? which is the cause of the problem?

Hmm, weird. Is it possible that airtime-analyzer just crashed and needed to be restarted ? Or is it basically all imports are failing with liquidsoap and the python magic showing up again. If we can figure out the sequence of events we should open up a issue on github and try to get to the bottom of this.

Ubuntu Trusty - LT 3.0.0-alpha.4. I also started getting exactly the same a week ago. I found this thread, did some digging with helpful pointers from above, and found that python-magic was somehow not installed. I installed it with a std. apt-get, restarted airtime analyzer and it sprang into life. I had been playing with eyeD3 (also Python) so maybe that uninstalled it? No idea, really, but the timing does seem to be suspicious with regard to other reports, but if it reoccurs I will try reinstalling and ‘holding’ it.

Definetly, eyeD3 needs python-magic to work properly. When you installed the package it was automatically installed. I had the same problem as I use eyeD3 and it complains about the missing python-magic.