jellyfin / mopidy-jellyfin

Jellyfin Extension for Mopidy
https://jellyfin.org
Apache License 2.0
93 stars 16 forks source link

Jellyfin API authentication #85

Closed sprtm closed 3 years ago

sprtm commented 3 years ago

Hello, I don't know if this is bug/issue, or if I'm doing things wrong. When I launch Mopidy it can't connect to Jellyfin. According to the error message no authentication token is found. I know how to generate an API key in Jellyfin, but I don't understand how to provide the key to Mopidy?

ERROR    2020-09-03 18:05:56,227 [53596:MainThread] mopidy.commands
  Got un-handled exception from JellyfinBackend
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/mopidy/commands.py", line 241, in _actor_error_handling
    yield
  File "/usr/local/lib/python3.8/site-packages/mopidy/commands.py", line 405, in start_backends
    backend = backend_class.start(
  File "/usr/local/lib/python3.8/site-packages/pykka/_actor.py", line 91, in start
    obj = cls(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/backend.py", line 26, in __init__
    self.remote = JellyfinHandler(config)
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/remote.py", line 82, in __init__
    self._login()
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/remote.py", line 96, in _login
    auth_details = self.http.post(
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/http.py", line 83, in post
    raise Exception('Cant connect to Jellyfin API')
Exception: Cant connect to Jellyfin API
ERROR    2020-09-03 18:05:56,265 [53596:MainThread] mopidy.commands
  Got un-handled exception from EventMonitorFrontend
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/mopidy/commands.py", line 241, in _actor_error_handling
    yield
  File "/usr/local/lib/python3.8/site-packages/mopidy/commands.py", line 438, in start_frontends
    frontend_class.start(config=config, core=core)
  File "/usr/local/lib/python3.8/site-packages/pykka/_actor.py", line 91, in start
    obj = cls(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/frontend.py", line 23, in __init__
    self.token = self._read_token(config)
  File "/usr/local/lib/python3.8/site-packages/mopidy_jellyfin/frontend.py", line 233, in _read_token
    raise Exception('No authentication token found')
Exception: No authentication token found
mcarlton00 commented 3 years ago

You're a little backwards on how it works, but that's ok. There's some room for improvement in those error messages.

Anytime you authenticate to the server with a user, it will give you an authentication token. You don't need a separate API token from the server outside of that. What the error is saying that mopidy has failed to reach the server for some reason, so it hasn't been able to receive that authentication token.

What does your config file for mopidy look like? As an example, this is mine right now:

[jellyfin]
hostname = http://192.168.0.200:8096
username = Matt
password = mysuperawesomepassword
libraries = Music
watched_status = True
sprtm commented 3 years ago

Aha, I understand. This is how my Mopidy conf looks:

[jellyfin]
hostname = http://10.0.1.4:8096
username = myusername
password = mypassword

I tried with and without http, and also changed the password, to no avail.

sprtm commented 3 years ago

Maybe I should add this, this is what's displayed before the error messages:

INFO     2020-09-03 18:47:10,675 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 0 with problem: Expecting value: line 1 column 1 (char 0)
INFO     2020-09-03 18:47:10,678 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 1 with problem: Expecting value: line 1 column 1 (char 0)
INFO     2020-09-03 18:47:10,681 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 2 with problem: Expecting value: line 1 column 1 (char 0)
INFO     2020-09-03 18:47:10,684 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 3 with problem: Expecting value: line 1 column 1 (char 0)
INFO     2020-09-03 18:47:10,688 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 4 with problem: Expecting value: line 1 column 1 (char 0)
INFO     2020-09-03 18:47:10,691 [53990:MainThread] mopidy_jellyfin.http
  Jellyfin connection on try 5 with problem: Expecting value: line 1 column 1 (char 0)

And right now I discovered several of these in the Jellyfin log:

[2020-09-03 18:55:39.456 +02:00] [ERR] [32] Emby.Server.Implementations.HttpServer.HttpListenerHost: Could not find handler for "/jellyfin/web/index.html/Users/AuthenticateByName"
[2020-09-03 18:55:39.456 +02:00] [ERR] [32] Emby.Server.Implementations.HttpServer.HttpListenerHost: Error processing request: "Unable to find the specified file". URL: "http://10.0.1.4:8096/jellyfin/web/index.html/Users/AuthenticateByName?format=json"
mcarlton00 commented 3 years ago

That's expected. If it fails to make an api call, it repeats the call a few times to try for a successful response.

You have a baseurl set on your server, don't you? Try hostname = http://10.0.1.4:8096/jellyfin

sprtm commented 3 years ago

Yes, progress after I added the baseurl to the hostname. To make things simple I removed the baseurl from Jellyfin, restarted the server, and removed it from the Mopidy conf. It still fails though. Now with this error:

AssertionError: Cannot add URI scheme 'jellyfin' for JellyfinBackend, it is already handled by JellyfinBackend

sprtm commented 3 years ago

For some reason the [jellyfin] part showed up twice when running "mopidy config", even though it wasn't double in the conf file itself. Even when the part was removed from the conf file, it showed up when running "mopidy config". After a clean install of Mopidy and mopidy-jellyfin, it now works. Thanks for pointing me in the right direction!