pimusicbox / mopidy-websettings

An easy to use Settings page for Mopidy and Pi MusicBox, editable in the browser
Apache License 2.0
32 stars 12 forks source link

Multiline config options not supported #29

Open kingosticks opened 5 years ago

kingosticks commented 5 years ago

I'm getting this error message, which makes no sense to me.

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1467, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mopidy_websettings/__init__.py", line 96, in get
    configValue = iniconfig.get(item, {}).get(subitem, None)
UnboundLocalError: local variable 'iniconfig' referenced before assignment

Originally posted by @gmkey in https://github.com/pimusicbox/mopidy-websettings/issues/26#issuecomment-477555070

kingosticks commented 5 years ago

Do you not get a "Could not load ini file!" error message in your log before the traceback? That's the only situation where the variable isn't defined. And that could be because you config_file setting is incorrect?

gmkey commented 5 years ago

Short answer: yes, the error kicks off with: mopidy_websettings: Could not load ini file! Parsing failed with several errors. Problem is, I don't know which file it is looking for. I've tested it with the version from the repo. and it reports: Could not load ini file! Parsing failed with several errors. First error at line 14. But please provide some guidance on the settingspec.ini file.

Sorry, I've been busy. So let me state my situation.

  1. Fresh install of raspbian 9.8
  2. mopidy installed from apt with these packages:
    • mopidy/stable,now 2.2.2-1 all
    • mopidy-tunein/stable,now 0.4.1-2
  3. the mopidy apt repo doesn't contain any package called mopidy-websettings
  4. installed mopidy-websettings from pip version 0.2.3 (it does contain a reference to the original writer: Home-page: https://github.com/woutervanwijk/mopidy-websettings)
  5. after restarting mopidy, the first call on http://raspberrypi.local:6680/settings/ returns a config_
2019-04-01 09:42:02,408 ERROR [21132:HttpServer] mopidy_websettings: Could not load ini file! Parsing failed with several errors.
First error at line 14.
2019-04-01 09:42:02,420 ERROR [21132:HttpServer] tornado.application: Uncaught exception GET /settings/ (myremoteip)
HTTPServerRequest(protocol='http', host='raspberrypi.local:6680', method='GET', uri='/settings/', version='HTTP/1.1', remote_ip='myremoteip', headers={'Accept-Language': 'nl-nl', 'Accept-Encoding': 'gzip, deflate', 'Host': 'raspberrypi.local:6680', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15', 'Connection': 'keep-alive', 'Referer': 'http://raspberrypi.local:6680/mopidy/', 'Upgrade-Insecure-Requests': '1'})
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1467, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mopidy_websettings/__init__.py", line 95, in get
    configValue = iniconfig.get(item, {}).get(subitem, None)
UnboundLocalError: local variable 'iniconfig' referenced before assignment
2019-04-01 09:42:02,434 ERROR [21132:HttpServer] tornado.access: 500 GET /settings/ (192.168.181.39) 685.96ms
kingosticks commented 5 years ago

The readme contains a little bit of guidence on this but maybe its not as clear as it could be:

config_file = /etc/mopidy/mopidy.conf

Make sure the config file is writable by the user under which mopidy is running! 

The config file being referred to in the above is the "ini file" referred to in the error message (Mopidy's config file is formatted as an .ini file). Basically, you need to set the websettings config setting to point to where your Mopidy config file is located on your system. Normally this is simply the location of the file you are editing. If you are running Mopidy as a service then the default should already be correct. Otherwise you'll need to change it to something like /home/pi/.config/mopidy/mopidy.conf.

There are a few other reasons that reading the file can fail so let me know if this still isn't working. I'll change the docs and error message to be more explicit anyway so thanks for reporting.

Oh, and to be clear, don't worry about "settingspec.ini", that shouldn't be the problem. Users don't have to do anything with that file.

gmkey commented 5 years ago

Figured it out. If running on a default Pi config of Mopidy, it loads configuration files from the default settings. The only way to ensure the web settings work is to actually export the values of mopidyctl config into /etc/mopidy/mopidy.conf and making sure that the values presented as an ordered list e.g.:

excluded_file_extensions =
  .directory
  .html
  .jpeg
  .jpg
  .log
  .nfo
  .png
  .txt

are entered as a comma separated value e.g.

excluded_file_extensions = .directory,.html,.jpeg,.jpg,.log,.nfo,.png,.txt

Maybe adding this to the Readme might actually make the installation somewhat easier.

But many thanks for pointing me in the right direction!

kingosticks commented 5 years ago

This isn't supposed to be required so this sounds like is a functional bug rather than a documentation issue. Those multi-line options are totally unsupported in PiMusicbox (which this project was originally created for) but I thought ConfigObj itself supported them so I'm a bit puzzled why this falls over.

kingosticks commented 5 years ago

Turns out ConfigObj's support for multiline values is really limited and requires you to quote the list. Which is not what Mopidy does with it's lists. I'm not sure there's a way we can keep using ConfigObj, I'm going to look at using Mopidy internal config routines.