Usernames with # in cause failure
When using an account where the username has a hash (#) in it, the daemon connects but then fails and exists. Full log with anonymisation:
Oct 24 09:06:20 myhostname Spotifyd[5380]: No config file specified. Running with default values
Oct 24 09:06:20 myhostname Spotifyd[5380]: Daemonizing running instance
Oct 24 09:06:20 myhostname Spotifyd[5380]: Detached from shell, now running in background.
Oct 24 09:06:20 myhostname Spotifyd[5380]: Using software volume controller.
Oct 24 09:06:20 myhostname Spotifyd[5380]: Connecting to AP "gew1-accesspoint-a-l4zp.ap.spotify.com:443"
Oct 24 09:06:21 myhostname Spotifyd[5380]: Authenticated as "username##" !
Oct 24 09:06:21 myhostname Spotifyd[5380]: Country: "GB"
Oct 24 09:06:21 myhostname Spotifyd[5380]: Using alsa sink
Oct 24 09:06:21 myhostname Spotifyd[5380]: error 400 for uri hm://remote/user/username##/
Oct 24 09:06:21 myhostname Spotifyd[5380]: error 400 for uri hm://remote/user/username##/
Oct 24 09:06:21 myhostname Spotifyd[5380]: Caught panic with message: called `Result::unwrap()` on an `Err` value: MercuryError
When searching Spotify API for my username, I have to encode the hash (username%23%23) so that might be what's required here, but I can't authenticate with it encoded to test that.
I know, stupid question, but your username actually contains hashes, does it? And does your entry look like this?
username = username##
Second, we pass down the username and password to librespot, which is responsible for connecting to the Spotify Connect service. This line calls their get_credentials call, which then calls the responsible hm:// backend.
To make sure that it is the encoding, would you mind running the following two commands?
spotifyd --no-daemon --username 'username##'
spotifyd --no-daemon --username 'username%23%23'
Make sure to add other necessary flags if needed (like backend and use-keyring).
The first should obviously fail. For the second, I'm just curious if that actually works :)
Note: The error gets thrown here: https://github.com/librespot-org/librespot/blob/431be9e847a584d374ec44e7c138525dd8fbb9d6/core/src/mercury/mod.rs#L195
Yep, it seems to be one character that spotify allow in usernames for whatever reason, and it makes it easy to get a short username :smile:
It fails if I have the username in the config file, so I have to pass it as a parameter every time although that isn't a huge deal
Both those commands fail, but for different reasons:
tom@hostname:~$ spotifyd --no-daemon --username 'username##' --password 'password'
09:58:53 [INFO] No config file specified. Running with default values
09:58:53 [INFO] Using software volume controller.
09:58:53 [INFO] Connecting to AP "gew1-accesspoint-a-5gzt.ap.spotify.com:443"
09:58:53 [INFO] Authenticated as "username##" !
09:58:53 [INFO] Country: "GB"
09:58:53 [INFO] Using alsa sink
09:58:53 [WARN] error 400 for uri hm://remote/user/username##/
09:58:53 [WARN] error 400 for uri hm://remote/user/username##/
09:58:53 [ERROR] Caught panic with message: called `Result::unwrap()` on an `Err` value: MercuryError
tom@hostname:~$ spotifyd --no-daemon --username 'username%23%23' --password 'password'
09:59:03 [INFO] No config file specified. Running with default values
09:59:03 [INFO] Using software volume controller.
09:59:03 [INFO] Connecting to AP "gew1-accesspoint-a-dclp.ap.spotify.com:443"
09:59:03 [ERROR] Caught panic with message: Authentication failed with reason: BadCredentials
On the official client, I can log in with username##, but my actual spotify URI is spotify:user:username%23%23
Ok, so librespot seems to log you in properly and encodes the string during that process. But calling the appropriate URI afterwards fails because the URI is not encoded. I'll report this back to librespot and see what they'll say.
I was pretty sure that the second one would fail, it's basically just another username then.
For why this doesn't work in the config. Every hashtag gets interpreted as a comment starter. So your username is internally getting parsed as 'username'. This will get fixed with the v1.0 milestone where we'll move to a better config file format, TOML. Our current (hacky) parser assumes every hashtag is a comment (my bad), because I thought no-one would ever use a hashtag in their names AND use this project :D
If you have time and want to tinker around with it, the parser logic is here: https://github.com/Spotifyd/spotifyd/blob/265af88559ce335a572b5276195578205c2ed26d/src/config.rs#L390-L406
You'd have to add a check for the hashtag in some way. I guess looking for the character on its left and checking if it is a whitespace should be enough to distinguish it from comments. So there would be a check right after line 400. Something like
let last_index = ...
if !l.char_at(last_index - 1).is_whitespace() {
l
} else {
l.drain(..last_index).collect()
}
Not sure about the method calls here but the logic and idea should be right.
Perfect, thanks for looking into it!
In regards to hash being parsed as a comment, it makes sense really, for a basic parser I think that's a reasonable assumption to make.
I haven't used rust before but might have a play around with it when I've got some spare time, although it's not mission critical as long as the CLI param works :man_shrugging:
Looking at the parser code I think you can work around this issue by adding an extra # at the end of the line.
e.g. username = username## #
this should treat the last # as the start of the comment then trim the space
Dang, that's actually a pretty nice workaround
This also makes passwords with # fail.
Yo, that is a known issue. But we only had one occurrence of someone who used hashtags in their password. Most people do not so...
Yo, that is a known issue. But we only had one occurrence of someone who used hashtags in their password. Most people do not so...
Gotcha. Well I changed it to a longer password with no characters. Still trying to see if I want to replace spotify app. Seems I can't search my liked songs, but the loading speed is much welcomed.
I mean, spotifyd is just a playback device. You still need another program anyway. It just shows up as a connect device. If you want to control the music directly (like choosing longs etc.) you need another client. Either a community driven one (like TUI based ones) or a mobile app or desktop app.
I mean, spotifyd is just a playback device. You still need another program anyway. It just shows up as a connect device. If you want to control the music directly (like choosing longs etc.) you need another client. Either a community driven one (like TUI based ones) or a mobile app or desktop app.
You are right. I am using spt at the moment. I got mixed up, but you're right, spotifyd is just the playback device.
But we only had one occurrence of someone who used hashtags in their password.
Another one that uses # on passwords: my wife. I've lost a lot of time to identify the problem. Maybe is not a bad idea consider it as a possibility.
I think you can work around this issue by adding an extra # at the end of the line.
On config file, removing spaces between name and value seem to work also.
i.e.: password=#123pass besides password = #123pass
On config file, removing spaces between name and value seem to work also.
That's because comments are defined as whitespace#, which doesn't get applied when you leave out the space around the equals sign.
In a slightly related note my username has a hyphen at the beginning, and it is interpreted as an argument. ~~EDIT: ok, I just needed escaping it better in the CLI with two backslashes~~ EDIT2: ok nvm, it doesn't interpret it right
Does it work if you use a config file?
But we only had one occurrence of someone who used hashtags in their password.
Another one that uses # on passwords: my wife. I've lost a lot of time to identify the problem. Maybe is not a bad idea consider it as a possibility.
I think you can work around this issue by adding an extra # at the end of the line.
On config file, removing spaces between name and value seem to work also. i.e.:
password=#123passbesidespassword = #123pass
I'm having this issue as well, It works if I configure directly in the cli but the config file gets confused with the #. Had to change the password
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.