librespot-org / librespot-java

The most up-to-date open source Spotify client
Apache License 2.0
380 stars 93 forks source link

MercuryException: status: 403 #370

Open amethystant opened 3 years ago

amethystant commented 3 years ago

Describe the bug When trying to connect to my spotify connect device that I set up with librespot autoconf, I get the below exception. The jar doesn't crash but the connection doesn't proceed, basically I click the device in the menu and nothing happens.

To Reproduce Download the spotify player jar (on a Windows machine). Run it to generate the config file and then stop it. Open the firewall ports as instructed in the README. Edit the generated config file and add the random port you opened, change nothing else and save. Run the jar again and leave running. Open any spotify client app and in the menu of available devices you see 'librespot-java'. Click it - nothing happens and you're not connected. Check the output of the running jar and you'll see the exception below.

Expected behavior After performing the steps above, I expect me spotify client to be connected to my spotify connect device and when I play music it gets played on the computer running the jar.

Screenshots/Stracktraces/Logs

xyz.gianlu.librespot.mercury.MercuryClient$MercuryException: status: 403
        at xyz.gianlu.librespot.mercury.MercuryClient.sendSync(MercuryClient.java:106) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.core.TokenProvider.getToken(TokenProvider.java:68) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.core.TokenProvider.get(TokenProvider.java:79) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.dealer.DealerClient.connect(DealerClient.java:79) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.core.Session.authenticate(Session.java:353) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.core.Session.access$600(Session.java:75) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.core.Session$Builder.create(Session.java:1021) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer.handleAddUser(ZeroconfServer.java:367) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer.access$200(ZeroconfServer.java:56) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handleRequest(ZeroconfServer.java:499) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handle(ZeroconfServer.java:574) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.lambda$run$1(ZeroconfServer.java:482) ~[librespot-player-1.6.0.jar:1.6.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_281]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_281]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_281]
2021-06-01 10:32:59,765 ERROR ZeroconfServer:501 - Failed handling addUser!
java.net.SocketException: Software caused connection abort: socket write error
        at java.net.SocketOutputStream.socketWrite0(Native Method) ~[?:1.8.0_281]
        at java.net.SocketOutputStream.socketWrite(Unknown Source) ~[?:1.8.0_281]
        at java.net.SocketOutputStream.write(Unknown Source) ~[?:1.8.0_281]
        at xyz.gianlu.librespot.ZeroconfServer.handleAddUser(ZeroconfServer.java:382) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer.access$200(ZeroconfServer.java:56) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handleRequest(ZeroconfServer.java:499) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.handle(ZeroconfServer.java:574) ~[librespot-player-1.6.0.jar:1.6.0]
        at xyz.gianlu.librespot.ZeroconfServer$HttpRunner.lambda$run$1(ZeroconfServer.java:482) ~[librespot-player-1.6.0.jar:1.6.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_281]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_281]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_281]

Version/Commit Downloaded jar librespot-player-1.6.0.jar

devgianlu commented 3 years ago

That's interesting and looks very much like the issue we are having with the new Facebook auth flow. What version of the official client are you using?

amethystant commented 3 years ago

it's 1.1.60.672.g6ad9c215-a on windows 10. also i've just tried connecting to the device using the android app and all works as expected (that's version 8.6.30.889). also i tried it from my macbook with the same version of the spotify app and that also worked (the Connect device still being the original windows machine). could it be caused by trying to connect from the same system on which the zeroconf server is running?

devgianlu commented 3 years ago

could it be caused by trying to connect from the same system on which the zeroconf server is running?

That shouldn't be the issue. Can you try logging out and logging in again from the problematic device to see if that fixes it?

amethystant commented 3 years ago

yeah, unfortunately that didn't help :/

jcadduono commented 3 years ago

I too am having the exact same problem, and had to go to USER_PASS for now which sucks because it only allows the logged in user to stream to the device. Client version is Windows 10 64-bit 1.1.61.583.gad060c66-a spocon/librespot 1.6.0 on Debian bullseye amd64 Looks like Spotify did something weird with their Windows desktop client.

rpardini commented 2 years ago

This same exception started happening with a MacOS Spotify Client (Spotify for macOS (Intel) 1.1.74.631.g0b24d9ad)) this last week. I reset everything and nothing, the dealer keeps on getting 403. Connecting from Android Spotify works (and then after that, the Mac Spotify can control the session).

jcadduono commented 2 years ago

At the top right of the desktop app, select your username, and go to Account. You should be on the “Account overview” page. You will see your Spotify “Username” there, which is a long string of randomized characters. Save that. Now go to the “Set device password” page and set a password for your account.

Now log out of the Spotify desktop app, and log in without using Facebook, by using the (long random characters) username & password you just set.

Now the desktop app will send normal Spotify access tokens over Spotify Connect and it should work fine (no more 403 errors)!

rpardini commented 2 years ago

@jcadduono Confirmed working. Thanks! I'm getting rid of Facebook anyway. (I previously have confused this with the user/pass settings in librespot-java config or cmdline options, which is inconvenient: it does not allow 2nd/3rd users with their own accounts.)

powellc commented 1 year ago

I already use a non-Facebook session key from user/pass and am having problems with 403 responses from Mercury regardless of which device I am logged in on (phone, computer, web). Any one have thoughts on what could be causing the permission issues this time?