Samik081 / beets-beatport4

Beatport API v4 compatible beets plugin
MIT License
26 stars 2 forks source link

Crash when beatport_token.json is present but has wrong format #11

Closed mkataja closed 1 year ago

mkataja commented 1 year ago

Got the following traceback after installing and configuring the plugin with beatport username and password and running beets import:

Traceback (most recent call last):
  File "~/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "~/.pyenv/versions/3.8.10/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/__main__.py", line 24, in <module>
    main(sys.argv[1:])
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/ui/__init__.py", line 1285, in main
    _raw_main(args)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/ui/__init__.py", line 1272, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/ui/commands.py", line 973, in import_func
    import_files(lib, paths, query)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/ui/commands.py", line 943, in import_files
    session.run()
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/importer.py", line 337, in run
    plugins.send('import_begin', session=self)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/plugins.py", line 488, in send
    result = handler(**arguments)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beets/plugins.py", line 145, in wrapper
    return func(*args, **kwargs)
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beetsplug/beatport4.py", line 528, in setup
    beatport_token = BeatportOAuthToken(json.load(f))
  File "~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/beetsplug/beatport4.py", line 47, in __init__
    self.access_token = str(data['access_token'])
KeyError: 'access_token'

I noticed ~/.config/beets/beatport_token.json already exists. I suppose this file was left by the old beatport plugin (?) and is probably not in the format beatport4 expects, hence the crash. The issue was resolved simply by removing the file.

Samik081 commented 1 year ago

Hey, thank you for reporting this issue! :) This seems right, the old token format will probably not be parsed correctly. I will fix this next week.

Samik081 commented 1 year ago

Hey @mkataja, took me while, and sorry for that. This issue should be already fixed in the v0.3.3 with https://github.com/Samik081/beets-beatport4/commit/8171cfceea7ddc525493fe3b3e05ca1c6073d0c4