BlitterStudio / MB_SubSonic

MusicBee SubSonic plugin
GNU General Public License v3.0
110 stars 14 forks source link

The server did not respond to ping as expected. But curl gives correct response. #67

Closed xinstein closed 2 years ago

xinstein commented 2 years ago

the plugin gives The server did not respond to ping as expected error, meanwhile the web server logs 200 response. When I copy the same request (retrieved from web server log) and do it via curl, I get a normal-looking response:

StatusCode        : 200
StatusDescription : OK
Content           : <?xml version="1.0" encoding="UTF-8"?>
                    <subsonic-response status="ok" version="1.16.1"/>

RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Pragma: no-cache
                    Content-Length: 89
                    Content-Type: application/xml
                    Date: Sat, 07 May 2022 05:50:39 GMT
                    Expires: Thu, 19 Nov 1981 08:52:00 GMT
                    Set-Cookie: o...

When I hit save, apply, save. Musicbee UI shows a Detected a subsonic server at lower left bar (hardly noticeable).

My server is a nextcloud music server with a self-signed ssl certificate and the path is https://my.host.name:myport/apps/music/subsonic. My configuration of the plugin:

Protocol: https
Hostname: my.host.name
Port: myport
Path: /apps/music/subsonic
Username: myusername 
Password: *********

My server works perfectly with Ultrasonic android app and plaintext authentication.

Also, what's the difference between Token-based and hex-enc authentication? Both requests are identical as logged by my webserver.

midwan commented 2 years ago

@xinstein Regarding the auth methods, you can check the details on the Subsonic API here: http://www.subsonic.org/pages/api.jsp The recommended way for newer versions is to use Token-based auth.

The Ping response error is a bit strange, since it seems that the content you posted above is correct. It might be an internal error happening for some reason, as it will also show that message if that happens. However, since you get a "Detected a Subsonic server" message on MusicBee, that would indicate that it got a ping response from the server at least on startup.

I'm pushing a new update which includes support for ownCloud music servers, it might help in your case as well.

midwan commented 2 years ago

@xinstein Did you get a chance to try the latest release? Did that help at all? I'm working on a few more improvements in the meantime...

midwan commented 2 years ago

@xinstein Looks like the NextCloud Music app implementation does not support Token-based authentication. I managed to set up a docker image with it to test it here, and this is what I get back from a Ping:

<subsonic-response status="failed" version="1.16.1">
  <error code="41" message="Token-based authentication not supported"/>
</subsonic-response>

This explains your error message above, when using Token-based authentication. The problem is, based on the API version standard defined by Subsonic, Token-based authentication is available since 1.13 and so this should be supported on 1.16.1 which this instance reports it's using.

Switching to Hex-encoded authentication fixes this for Nextcloud, but I couldn't test further because I kept getting "Invalid Login" errors after that. I've only set up an admin account, so I don't know why it fails for me, but I'll keep testing it.

midwan commented 2 years ago

@xinstein Scratch the above, I managed to login (missed the part were the app only allows it's own generated API keys to login, not the Nextcloud credentials).

The next issue I found, which also causes the Ping response to fail, is the content of the response itself (compared to the expected one). Notice the differences below...

Nextcloud Ping "OK" response:

<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response status="ok" version="1.16.1"/>

Subsonic / Airsonic-advanced Ping "OK" response:

<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.15.0"/>

the xmlns="http://subsonic.org/restapi" tag is missing, and the deserialization fails, triggering the failed Ping response. I'll look into this more...

midwan commented 2 years ago

After further testing, this definitely is an issue with Nextcloud's Music app implementation (at least, specifically that of the Subsonic API). It's not entirely correct, so the automatic deserialization of the response fails, leading to the content not being recognized as a valid response.

All other Subsonic compatible implementations that I've tested work fine, except this one (at least, so far). The Android app you mentioned has a different way of mapping the response to classes, so it's as strict (which is why it works there). For this plugin, I'm using the official xsd for the Subsonic API published here: http://www.subsonic.org/pages/inc/api/schema/subsonic-rest-api-1.16.1.xsd

I don't think there's much more I can do from my side for now, but if this is reported to the maintainer(s) of the Music app for Nextcloud, perhaps they can fix their Subsonic API responses to be more compliant.

xinstein commented 2 years ago

Thank you, sorry I forgot to check my email for days.

I'll report this to the nextcloud music app.