thesquelched / suggestive

Python MPD client with integrated Last.FM support
BSD 2-Clause "Simplified" License
4 stars 0 forks source link

crash on startup #7

Closed carnager closed 8 years ago

carnager commented 8 years ago

When starting up suggestive it crashes with a KeyError.

carnager@caprica ~/suggestive/suggestive > suggestive             
Traceback (most recent call last):
  File "/usr/bin/suggestive", line 9, in <module>
    load_entry_point('suggestive==0.4.0', 'console_scripts', 'suggestive')()
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 586, in main
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 566, in run
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 223, in __init__
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 53, in __init__
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 97, in initialize_buffers
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 114, in create_playlist_buffer
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 471, in __init__
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 90, in __init__
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 220, in update_model
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 191, in track_models
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 165, in playlist_tracks
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 140, in database_tracks_from_mpd
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 140, in <listcomp>
KeyError: 'flac/Motorpsycho/1993 Demon Box/CD 1/01-Waiting for the One.flac'
ghost commented 8 years ago

Having the same issue.

Traceback (most recent call last):
  File "/usr/local/bin/suggestive", line 9, in <module>
    load_entry_point('suggestive==0.4.0', 'console_scripts', 'suggestive')()
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 586, in main
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 566, in run
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 223, in __init__
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 53, in __init__
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 97, in initialize_buffers
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 114, in create_playlist_buffer
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 471, in __init__
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 90, in __init__
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 220, in update_model
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 191, in track_models
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/playlist.py", line 165, in playlist_tracks
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 140, in database_tracks_from_mpd
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 140, in <listcomp>
KeyError: 'p/Pearl Jam/Rearviewmirror Greatest Hits 1991–2003/02 Alive.flac'
thesquelched commented 8 years ago

Can you backup your music.db file in your conf directory (usually $HOME/.suggestive) and try running it again? I'm wondering if this is happening on initialization or subsequent runs.

thesquelched commented 8 years ago

Sorry, you have to delete the music.db file after backing it up.

thesquelched commented 8 years ago

Also, how big is your current playlist? You can open another mpd app like ncmpcpp to check.

ghost commented 8 years ago

@thesquelched After backing up and moving music.db it appeared to be working at first then I got this.

Traceback (most recent call last):
  File "/usr/local/bin/suggestive", line 9, in <module>
    load_entry_point('suggestive==0.4.0', 'console_scripts', 'suggestive')()
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 586, in main
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 554, in run
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 755, in update_mpd
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 518, in load
  File "/usr/local/lib/python3.5/dist-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 459, in check_duplicates
  File "/usr/local/lib/python3.5/dist-packages/python_mpd2-0.5.5-py3.5.egg/mpd.py", line 629, in decorator
  File "/usr/local/lib/python3.5/dist-packages/python_mpd2-0.5.5-py3.5.egg/mpd.py", line 252, in _execute
  File "/usr/local/lib/python3.5/dist-packages/python_mpd2-0.5.5-py3.5.egg/mpd.py", line 279, in _write_command
  File "/usr/local/lib/python3.5/dist-packages/python_mpd2-0.5.5-py3.5.egg/mpd.py", line 259, in _write_line
  File "/usr/lib/python3.5/socket.py", line 593, in write
    return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe

The first few runs I had to create a config file. It might be screwing up the import if the config file is missing on the first run.

According to mpd I have 21879 songs in my database.

thesquelched commented 8 years ago

@gregf interesting. You shouldn't even be able to run it without a conf file (you should get an error like Could not determine LastFM API key; see https://github.com/thesquelched/suggestive#configuration)

thesquelched commented 8 years ago

Can you pull down the mpd_track_key_error branch and give that a shot? I think the issue might be that the track list is getting modified in the middle of that function execution.

carnager commented 8 years ago

deleting music.db seems to work. it's initializing right now. Seems suggestive is creating a music.db file even if no config is present. probably should catch that.

Anyway, now i get this:

carnager@caprica ~/.suggestive > suggestive 
Music database not found; initializing...
Traceback (most recent call last):
  File "/usr/bin/suggestive", line 9, in <module>
    load_entry_point('suggestive==0.4.0', 'console_scripts', 'suggestive')()
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 586, in main
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/app.py", line 554, in run
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 755, in update_mpd
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 518, in load
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.0-py3.5.egg/suggestive/mstat.py", line 459, in check_duplicates
  File "/usr/lib/python3.5/site-packages/mpd.py", line 600, in decorator
    return wrapper(self, name, args, bound_decorator(self, returnValue))
  File "/usr/lib/python3.5/site-packages/mpd.py", line 238, in _execute
    return retval()
  File "/usr/lib/python3.5/site-packages/mpd.py", line 595, in decorator
    return function(self, *args, **kwargs)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 406, in _fetch_songs
    return self._fetch_objects(["file"])
  File "/usr/lib/python3.5/site-packages/mpd.py", line 394, in _fetch_objects
    return self._wrap_iterator(self._read_objects(delimiters))
  File "/usr/lib/python3.5/site-packages/mpd.py", line 358, in _wrap_iterator
    return list(iterator)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 316, in _read_objects
    for key, value in self._read_pairs():
  File "/usr/lib/python3.5/site-packages/mpd.py", line 295, in _read_pairs
    pair = self._read_pair(separator)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 286, in _read_pair
    line = self._read_line()
  File "/usr/lib/python3.5/site-packages/mpd.py", line 271, in _read_line
    raise ConnectionError("Connection lost while reading line")
mpd.ConnectionError: Connection lost while reading line
thesquelched commented 8 years ago

Strange that both of you are getting mpd connection errors, but maybe you just have much larger MPD databases than me and are seeing a timeout that I'm not. Anyway, I'll add connection retry logic to the affected functions.

thesquelched commented 8 years ago

Branch updated; give it a shot

carnager commented 8 years ago

still not working, but with added error :)

carnager@caprica ~/suggestive > suggestive 
Music database not found; initializing...
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 34, in wrapper
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 467, in check_duplicates
  File "/usr/lib/python3.5/site-packages/mpd.py", line 600, in decorator
    return wrapper(self, name, args, bound_decorator(self, returnValue))
  File "/usr/lib/python3.5/site-packages/mpd.py", line 238, in _execute
    return retval()
  File "/usr/lib/python3.5/site-packages/mpd.py", line 595, in decorator
    return function(self, *args, **kwargs)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 406, in _fetch_songs
    return self._fetch_objects(["file"])
  File "/usr/lib/python3.5/site-packages/mpd.py", line 394, in _fetch_objects
    return self._wrap_iterator(self._read_objects(delimiters))
  File "/usr/lib/python3.5/site-packages/mpd.py", line 358, in _wrap_iterator
    return list(iterator)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 316, in _read_objects
    for key, value in self._read_pairs():
  File "/usr/lib/python3.5/site-packages/mpd.py", line 295, in _read_pairs
    pair = self._read_pair(separator)
  File "/usr/lib/python3.5/site-packages/mpd.py", line 286, in _read_pair
    line = self._read_line()
  File "/usr/lib/python3.5/site-packages/mpd.py", line 271, in _read_line
    raise ConnectionError("Connection lost while reading line")
mpd.ConnectionError: Connection lost while reading line

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/suggestive", line 9, in <module>
    load_entry_point('suggestive==0.4.1', 'console_scripts', 'suggestive')()
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/app.py", line 590, in main
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/app.py", line 558, in run
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 770, in update_mpd
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 533, in load
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 38, in wrapper
AttributeError: 'MpdLoader' object has no attribute 'conf'
carnager commented 8 years ago

carnager@caprica ~/Rips > mpc stats Artists: 2154 Albums: 3573 Songs: 43235

thesquelched commented 8 years ago

Holy shit, I have no idea how you guys have such huge libraries. Well, I have some idea (hello, bittorrent!)

That error was a QA failure on my part. Branch updated with bugfix and ... gasp... TESTS

thesquelched commented 8 years ago

By the way, I really appreciate you guys helping me out here. I wasn't aware that anyone else was even using this. This was sort of a learning experience for me when I originally wrote it, and there's a lot I should do WRT performance, UX, etc, so I hope you'll stick with it!

ghost commented 8 years ago

That fixed it for me. Thanks!

carnager commented 8 years ago

@thesquelched believe it or not, it's all original CDs in my case. Let's say I am a freak.

Anyway. now it starts up, opens last.fm in a browser and asks me to press return. After hitting return i get:

Traceback (most recent call last):                                   12 Rounds - Jitter Juice - Hesitate
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner Rounds - Jitter Juice - Mug
    self.run()re 4 U                                                 12 Rounds - Jitter Juice - Strange Daze
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/threads.py", line 25, in newrun
    orig_run(self)Desire                                             12 Rounds - Jitter Juice - Keeling Over
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/threads.py", line 212, in runtting in the Sunshine
    lastfm = mstat.initialize_lastfm(conf)                           [0:56/4:04]
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/mstat.py", line 729, in initialize_lastfm
    return LastFM(config)
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/lastfm.py", line 35, in __init__
    self.client = self._initialize_client()
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/util.py", line 30, in wrapper
    return func(*args, **kwArgs)
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/lastfm.py", line 96, in _initialize_client
    self._authorize_application(client)
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/lastfm.py", line 72, in _authorize_application
    session_key = retry_function(client.auth.get_session, token)
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/util.py", line 48, in retry_function
    return decorator(lambda: func(*args, **kwargs))()
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/util.py", line 30, in wrapper
    return func(*args, **kwArgs)
  File "/usr/lib/python3.5/site-packages/suggestive-0.4.1-py3.5.egg/suggestive/util.py", line 48, in <lambda>
    return decorator(lambda: func(*args, **kwargs))()
  File "/usr/lib/python3.5/site-packages/pylastfm-0.2.0-py3.5.egg/pylastfm/api/auth.py", line 29, in get_session
    unwrap='session')['key']
  File "/usr/lib/python3.5/site-packages/pylastfm-0.2.0-py3.5.egg/pylastfm/api/api.py", line 11, in _request
    return self._client._request(*args, **kwargs)
  File "/usr/lib/python3.5/site-packages/pylastfm-0.2.0-py3.5.egg/pylastfm/client.py", line 279, in _request
    exc)
  File "<string>", line 2, in raise_from
pylastfm.error.APIError: Error 400: Bad Request
thesquelched commented 8 years ago

I believe that's what happens when you don't visit the URL and authorize the application with the lastfm API before hitting enter.

carnager commented 8 years ago

i did though, tried several times. always the same. And since there is no way currently to view your last.fm permissions since the new last.fm beta, I will blindly assume it's their fault

thesquelched commented 8 years ago

I wonder if there's anything relevant in the logs? Look for log.txt in your conf directory (by default, $HOME/.suggestive). FYI, when errors appear in the console like that, you can get the stack trace without the junk in the log file.

So the flow for initializing lastfm is basically:

  1. Get auth token from lastfm API
  2. Display URL (and attempt to open in browser) for lastfm page to authorize application
  3. User clicks "Yes, Allow Access" (I think that's what the buttons says) on said lastfm page to authorize the application. The page should then indicate that the application was authorized
  4. Back in suggestive, user hits a key
  5. Lastfm client checks with API as to whether the auth token was authorized on that webpage

The only way that flow breaks is if 1) the button on the lastfm webpage wasn't hit or b) lastfm's API broke (it happens more than you'd expect). You could try removing the session file {conf_dir}/session and then re-launching suggestive, which will force re-authorization.

carnager commented 8 years ago

Ok, it works now. I only added the api key and forgot the secret. Probably should tell the user on startup, if stuff is missing

thesquelched commented 8 years ago

Hmm... lastfm API returns a 403 error if the application wasn't authorized, so you're doing the right thing. The only way I've been able to cause a 400 error is if there's a typo in the api secret; can you check the value in your config of the api_secret option in the lastfm section? Make sure it matches the value shown in the Your API Accounts section of (the LastFM API site)[http://www.last.fm/api] when you click on the corresponding account. You should see, in a yellow box at the top of the page, Secret: is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

carnager commented 8 years ago

sorry, shouldnt have edited the comment. it was indeed the api secret

thesquelched commented 8 years ago

OK, cool. Was there a typo, or did you not have it in the config? Maybe I should make it clearer in the README that the secret is required.

carnager commented 8 years ago

It was completely missing

thesquelched commented 8 years ago

Oh, stupid me, I said it was optional. I'll change that in the readme for now, and then I'll work on making it actually optional. Thanks for your help!

EDIT: Updated in readme