[GH-ISSUE #277] [BUG] BadCredentials #51

Open
opened 2026-02-27 08:11:37 +03:00 by kerem · 43 comments
Owner

Originally created by @hazycora on GitHub (Jul 26, 2024).
Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/277

Describe the bug
Login fails on some accounts on some devices. My current guess is they're doing some kind of A/B test to phase out something this relies on? Maybe the protocol version needs to be updated?
Occurs not just here but also on the separate librespot-js project and librespot-java. The bug is not with some library-specific logic but with a change to Spotify- a fix here will likely also be able to be applied everywhere else.

To Reproduce

from librespot.core import Session

session = Session.Builder() \
    .user_pass("username", "password") \
    .create()

Expected behavior
The login should be successful.

Screenshots

Traceback (most recent call last):
  File "/home/hazy/tmp_a/test.py", line 7, in <module>
    .create()
     ^^^^^^^^
  File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 1634, in create
    session.authenticate(self.login_credentials)
  File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 939, in authenticate
    self.__authenticate_partial(credential, False)
  File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 1350, in __authenticate_partial
    raise Session.SpotifyAuthenticationException(ap_login_failed)
librespot.core.Session.SpotifyAuthenticationException: BadCredentials

Client Information (please complete the following information):

  • OS: Arch Linux
  • Python Version: 3.12.4
  • Library Version: Last snapshot (3b46fe560a)
Originally created by @hazycora on GitHub (Jul 26, 2024). Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/277 **Describe the bug** Login fails on *some* accounts on *some* devices. My current guess is they're doing some kind of A/B test to phase out something this relies on? Maybe the protocol version needs to be updated? Occurs not just here but also on the separate [librespot-js](https://npmjs.com/package/librespot) project and [librespot-java](https://github.com/librespot-org/librespot-java/issues/921). The bug is not with some library-specific logic but with a change to Spotify- a fix here will likely also be able to be applied everywhere else. **To Reproduce** ```python from librespot.core import Session session = Session.Builder() \ .user_pass("username", "password") \ .create() ``` **Expected behavior** The login should be successful. **Screenshots** ```sh Traceback (most recent call last): File "/home/hazy/tmp_a/test.py", line 7, in <module> .create() ^^^^^^^^ File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 1634, in create session.authenticate(self.login_credentials) File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 939, in authenticate self.__authenticate_partial(credential, False) File "/home/hazy/tmp_a/venv/lib/python3.12/site-packages/librespot/core.py", line 1350, in __authenticate_partial raise Session.SpotifyAuthenticationException(ap_login_failed) librespot.core.Session.SpotifyAuthenticationException: BadCredentials ``` **Client Information (please complete the following information):** - OS: Arch Linux - Python Version: 3.12.4 - Library Version: Last snapshot (3b46fe560ad829b976ce63e85012cff95b1e0bf3)
Author
Owner

@hazycora commented on GitHub (Jul 26, 2024):

If it can't be reproduced, I have a server that has this problem, and I'm up for helping in any way I can!

<!-- gh-comment-id:2253231806 --> @hazycora commented on GitHub (Jul 26, 2024): If it can't be reproduced, I have a server that has this problem, and I'm up for helping in any way I can!
Author
Owner

@kokarare1212 commented on GitHub (Jul 27, 2024):

I don't know the details, I suspect that your IP address has been blacklisted due to the number of login attempts?

<!-- gh-comment-id:2253740699 --> @kokarare1212 commented on GitHub (Jul 27, 2024): I don't know the details, I suspect that your IP address has been blacklisted due to the number of login attempts?
Author
Owner

@hazycora commented on GitHub (Jul 28, 2024):

given that this occurred the only time I had ever tried on this server, no I don't believe that

<!-- gh-comment-id:2254648357 --> @hazycora commented on GitHub (Jul 28, 2024): given that this occurred the only time I had ever tried on this server, no I don't believe that
Author
Owner

@shayanmaher commented on GitHub (Jul 28, 2024):

I don't know the details, I suspect that your IP address has been blacklisted due to the number of login attempts?

also i have this issue for login auth with this error raise Session.SpotifyAuthenticationException(ap_login_failed) librespot.core.Session.SpotifyAuthenticationException: BadCredentials

<!-- gh-comment-id:2254676451 --> @shayanmaher commented on GitHub (Jul 28, 2024): > I don't know the details, I suspect that your IP address has been blacklisted due to the number of login attempts? also i have this issue for login auth with this error `raise Session.SpotifyAuthenticationException(ap_login_failed) librespot.core.Session.SpotifyAuthenticationException: BadCredentials`
Author
Owner

@pdtan commented on GitHub (Jul 29, 2024):

I also got this error sometimes

<!-- gh-comment-id:2254815303 --> @pdtan commented on GitHub (Jul 29, 2024): I also got this error sometimes
Author
Owner

@shayanmaher commented on GitHub (Jul 29, 2024):

I also got this error sometimes

i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,...etc has this problem you can solve this issue by use a fresh ip

<!-- gh-comment-id:2255309229 --> @shayanmaher commented on GitHub (Jul 29, 2024): > I also got this error sometimes i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,...etc has this problem you can solve this issue by use a fresh ip
Author
Owner

@staniel359 commented on GitHub (Jul 29, 2024):

@kokarare1212 I've started to encounter this too.

<!-- gh-comment-id:2256065768 --> @staniel359 commented on GitHub (Jul 29, 2024): @kokarare1212 I've started to encounter this too.
Author
Owner

@IVIanuu commented on GitHub (Jul 29, 2024):

I also encounter this issue since today.. Any fix?

<!-- gh-comment-id:2256357442 --> @IVIanuu commented on GitHub (Jul 29, 2024): I also encounter this issue since today.. Any fix?
Author
Owner

@phuketbinaryt commented on GitHub (Jul 29, 2024):

Same issue here with the bad credentials.

<!-- gh-comment-id:2256455165 --> @phuketbinaryt commented on GitHub (Jul 29, 2024): Same issue here with the bad credentials.
Author
Owner

@dylenthomas commented on GitHub (Jul 29, 2024):

This just started happening to me today too, might be an issue with spotify's client? I tried on a MacBook with latest MacOS and my linux desktop, both having same issue. I also tried with the latest install of librespot, that was working yesterday.

Since this is happening to so many people they might have an issue with their api right now?

<!-- gh-comment-id:2256495292 --> @dylenthomas commented on GitHub (Jul 29, 2024): This just started happening to me today too, might be an issue with spotify's client? I tried on a MacBook with latest MacOS and my linux desktop, both having same issue. I also tried with the latest install of librespot, that was working yesterday. Since this is happening to so many people they might have an issue with their api right now?
Author
Owner

@clemwo commented on GitHub (Jul 29, 2024):

I also have this issue on a windows machine.

It's also being discussed in the librespot project directly here : https://github.com/librespot-org/librespot/issues/1308

Feels like spotify changed something on their end maybe?

<!-- gh-comment-id:2257166260 --> @clemwo commented on GitHub (Jul 29, 2024): I also have this issue on a windows machine. It's also being discussed in the librespot project directly here : https://github.com/librespot-org/librespot/issues/1308 Feels like spotify changed something on their end maybe?
Author
Owner

@rgon commented on GitHub (Jul 30, 2024):

i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,...

@shayanmaher happening to me on a residential IP. Definitely not data center blacklisting, but rather seems like a buggy rolled-out deploy in their end or rather some of their pesky A/B API testing

<!-- gh-comment-id:2257711729 --> @rgon commented on GitHub (Jul 30, 2024): > i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,... @shayanmaher happening to me on a residential IP. Definitely not data center blacklisting, but rather seems like a buggy rolled-out deploy in their end or rather some of their pesky A/B API testing
Author
Owner

@hazycora commented on GitHub (Aug 2, 2024):

I also got this error sometimes

i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,...etc has this problem you can solve this issue by use a fresh ip

this is not true. happens on all residential IPs ive tried now. that was absolutely just part of the rollout.

<!-- gh-comment-id:2266264611 --> @hazycora commented on GitHub (Aug 2, 2024): > > I also got this error sometimes > > i solve this problem it belongs to ip of datacenters which in blacklist popular Datacenters like hetzener,...etc has this problem you can solve this issue by use a fresh ip this is not true. happens on all residential IPs ive tried now. that was absolutely just part of the rollout.
Author
Owner

@TreeOfSelf commented on GitHub (Aug 2, 2024):

Happening to me as well.

<!-- gh-comment-id:2266267597 --> @TreeOfSelf commented on GitHub (Aug 2, 2024): Happening to me as well.
Author
Owner

@kokarare1212 commented on GitHub (Aug 3, 2024):

It appears that login using username and password has been discontinued.
https://github.com/librespot-org/librespot-java/issues/921#issuecomment-2258440907
Please use other login methods (e.g. zeroconf) or PR a new login method instead.

<!-- gh-comment-id:2266307428 --> @kokarare1212 commented on GitHub (Aug 3, 2024): It appears that login using username and password has been discontinued. https://github.com/librespot-org/librespot-java/issues/921#issuecomment-2258440907 Please use other login methods (e.g. zeroconf) or PR a new login method instead.
Author
Owner

@staniel359 commented on GitHub (Aug 3, 2024):

@kokarare1212 Could you then provide the instructions on how to use Zeroconf instead of Session?

<!-- gh-comment-id:2266650589 --> @staniel359 commented on GitHub (Aug 3, 2024): @kokarare1212 Could you then provide the instructions on how to use Zeroconf instead of Session?
Author
Owner

@realCmdData commented on GitHub (Aug 7, 2024):

Same issue for me, even changing IP's through a VPN doesn't work.

  File "C:\Users\myusername\AppData\Local\Programs\Python\Python310\lib\site-packages\librespot\core.py", line 1350, in __authenticate_partial
    raise Session.SpotifyAuthenticationException(ap_login_failed)
librespot.core.Session.SpotifyAuthenticationException: BadCredentials
<!-- gh-comment-id:2274189359 --> @realCmdData commented on GitHub (Aug 7, 2024): Same issue for me, even changing IP's through a VPN doesn't work. ``` File "C:\Users\myusername\AppData\Local\Programs\Python\Python310\lib\site-packages\librespot\core.py", line 1350, in __authenticate_partial raise Session.SpotifyAuthenticationException(ap_login_failed) librespot.core.Session.SpotifyAuthenticationException: BadCredentials ```
Author
Owner

@realCmdData commented on GitHub (Aug 7, 2024):

Same issue for me, even changing IP's through a VPN doesn't work.

  File "C:\Users\myusername\AppData\Local\Programs\Python\Python310\lib\site-packages\librespot\core.py", line 1350, in __authenticate_partial
    raise Session.SpotifyAuthenticationException(ap_login_failed)
librespot.core.Session.SpotifyAuthenticationException: BadCredentials

UPDATE:

Got it to work... Somehow... Still not quite sure how but I tried restarting my PC and deactivating my VPN, and it worked. Perhaps through trial and error? Or Spotify is blocking CLI requests that come from known VPN servers? I have no idea...

<!-- gh-comment-id:2274218969 --> @realCmdData commented on GitHub (Aug 7, 2024): > Same issue for me, even changing IP's through a VPN doesn't work. > > ``` > File "C:\Users\myusername\AppData\Local\Programs\Python\Python310\lib\site-packages\librespot\core.py", line 1350, in __authenticate_partial > raise Session.SpotifyAuthenticationException(ap_login_failed) > librespot.core.Session.SpotifyAuthenticationException: BadCredentials > ``` UPDATE: Got it to work... Somehow... Still not quite sure how but I tried restarting my PC and deactivating my VPN, and it worked. Perhaps through trial and error? Or Spotify is blocking CLI requests that come from known VPN servers? I have no idea...
Author
Owner

@pdtan commented on GitHub (Aug 8, 2024):

Please use other login methods (e.g. zeroconf)

Please provide the instructions on how to use Zeroconf instead of Session?

<!-- gh-comment-id:2274721566 --> @pdtan commented on GitHub (Aug 8, 2024): > Please use other login methods (e.g. zeroconf) Please provide the instructions on how to use Zeroconf instead of Session?
Author
Owner

@kokarare1212 commented on GitHub (Aug 8, 2024):

It is incomplete but should work.
See the original librespot-java for details.

Sample code can be found here.
Sessions within zeroconf should be accessible via these: zeroconf._ZeroconfServer__session

Remember I have very little time to devote to these projects.

<!-- gh-comment-id:2275142944 --> @kokarare1212 commented on GitHub (Aug 8, 2024): It is incomplete but should work. See the original [librespot-java](https://github.com/librespot-org/librespot-java/blob/dev/lib/src/main/java/xyz/gianlu/librespot/ZeroconfServer.java) for details. Sample code can be found [here](https://github.com/kokarare1212/librespot-python#use-zeroconf-for-login). Sessions within zeroconf should be accessible via these: `zeroconf._ZeroconfServer__session` Remember I have very little time to devote to these projects.
Author
Owner

@pdtan commented on GitHub (Aug 8, 2024):

https://github.com/kokarare1212/librespot-python#use-zeroconf-for-login zeroconf._ZeroconfServer__session

Very unclear. btw, I don't see _ZeroconfServer__session:

[INFO     09:58:35] Zeroconf HTTP server started successfully on port 58172!
[DEBUG    09:58:35] Using selector: EpollSelector
{'_ZeroconfServer__inner': <librespot.zeroconf.ZeroconfServer.Inner object at 0xffff8c9e2760>, '_ZeroconfServer__keys': <librespot.crypto.DiffieHellman object at 0xffff8c991f10>, '_ZeroconfServer__runner': <librespot.zeroconf.ZeroconfServer.HttpRunner object at 0xffff8c4a09d0>, '_ZeroconfServer__zeroconf': <zeroconf._core.Zeroconf object at 0xffff8c4a0c10>, '_ZeroconfServer__service_info': ServiceInfo(type='_spotify-connect._tcp.local.', name='librespot-python._spotify-connect._tcp.local.', addresses=[b'@nE\x8d'], port=58172, weight=0, priority=0, server='mail.', properties={b'CPath': b'/', b'VERSION': b'1.0', b'STACK': b'SP'}, interface_index=None)}
[DEBUG    09:58:36] Using selector: EpollSelector
<!-- gh-comment-id:2275431533 --> @pdtan commented on GitHub (Aug 8, 2024): > https://github.com/kokarare1212/librespot-python#use-zeroconf-for-login `zeroconf._ZeroconfServer__session` Very unclear. btw, I don't see `_ZeroconfServer__session`: ``` [INFO 09:58:35] Zeroconf HTTP server started successfully on port 58172! [DEBUG 09:58:35] Using selector: EpollSelector {'_ZeroconfServer__inner': <librespot.zeroconf.ZeroconfServer.Inner object at 0xffff8c9e2760>, '_ZeroconfServer__keys': <librespot.crypto.DiffieHellman object at 0xffff8c991f10>, '_ZeroconfServer__runner': <librespot.zeroconf.ZeroconfServer.HttpRunner object at 0xffff8c4a09d0>, '_ZeroconfServer__zeroconf': <zeroconf._core.Zeroconf object at 0xffff8c4a0c10>, '_ZeroconfServer__service_info': ServiceInfo(type='_spotify-connect._tcp.local.', name='librespot-python._spotify-connect._tcp.local.', addresses=[b'@nE\x8d'], port=58172, weight=0, priority=0, server='mail.', properties={b'CPath': b'/', b'VERSION': b'1.0', b'STACK': b'SP'}, interface_index=None)} [DEBUG 09:58:36] Using selector: EpollSelector ```
Author
Owner

@kingosticks commented on GitHub (Aug 12, 2024):

https://github.com/kokarare1212/librespot-python#use-zeroconf-for-login zeroconf._ZeroconfServer__session

Very unclear. btw, I don't see _ZeroconfServer__session:

[INFO     09:58:35] Zeroconf HTTP server started successfully on port 58172!
[DEBUG    09:58:35] Using selector: EpollSelector
{'_ZeroconfServer__inner': <librespot.zeroconf.ZeroconfServer.Inner object at 0xffff8c9e2760>, '_ZeroconfServer__keys': <librespot.crypto.DiffieHellman object at 0xffff8c991f10>, '_ZeroconfServer__runner': <librespot.zeroconf.ZeroconfServer.HttpRunner object at 0xffff8c4a09d0>, '_ZeroconfServer__zeroconf': <zeroconf._core.Zeroconf object at 0xffff8c4a0c10>, '_ZeroconfServer__service_info': ServiceInfo(type='_spotify-connect._tcp.local.', name='librespot-python._spotify-connect._tcp.local.', addresses=[b'@nE\x8d'], port=58172, weight=0, priority=0, server='mail.', properties={b'CPath': b'/', b'VERSION': b'1.0', b'STACK': b'SP'}, interface_index=None)}
[DEBUG    09:58:36] Using selector: EpollSelector

Forgive me for jumping in, but you have to actually use the zeroconf server to auth a client before a session will be created. Given the log you provided, it doesn't look like you did that.

<!-- gh-comment-id:2284173943 --> @kingosticks commented on GitHub (Aug 12, 2024): > > https://github.com/kokarare1212/librespot-python#use-zeroconf-for-login `zeroconf._ZeroconfServer__session` > > Very unclear. btw, I don't see `_ZeroconfServer__session`: > > ``` > [INFO 09:58:35] Zeroconf HTTP server started successfully on port 58172! > [DEBUG 09:58:35] Using selector: EpollSelector > {'_ZeroconfServer__inner': <librespot.zeroconf.ZeroconfServer.Inner object at 0xffff8c9e2760>, '_ZeroconfServer__keys': <librespot.crypto.DiffieHellman object at 0xffff8c991f10>, '_ZeroconfServer__runner': <librespot.zeroconf.ZeroconfServer.HttpRunner object at 0xffff8c4a09d0>, '_ZeroconfServer__zeroconf': <zeroconf._core.Zeroconf object at 0xffff8c4a0c10>, '_ZeroconfServer__service_info': ServiceInfo(type='_spotify-connect._tcp.local.', name='librespot-python._spotify-connect._tcp.local.', addresses=[b'@nE\x8d'], port=58172, weight=0, priority=0, server='mail.', properties={b'CPath': b'/', b'VERSION': b'1.0', b'STACK': b'SP'}, interface_index=None)} > [DEBUG 09:58:36] Using selector: EpollSelector > ``` Forgive me for jumping in, but you have to actually use the zeroconf server to auth a client before a session will be created. Given the log you provided, it doesn't look like you did that.
Author
Owner

@dracarys69 commented on GitHub (Aug 15, 2024):

idk about you guys i can still login fine with email and password and whenever i get BadCredentials issue i delete the credentials json and change my account password and it starts working again. tho its been a while since i had that issue

<!-- gh-comment-id:2291162843 --> @dracarys69 commented on GitHub (Aug 15, 2024): idk about you guys i can still login fine with email and password and whenever i get BadCredentials issue i delete the credentials json and change my account password and it starts working again. tho its been a while since i had that issue
Author
Owner

@g42ftw commented on GitHub (Aug 15, 2024):

Login with username/password via .user_pass() method is no longer possible: https://github.com/librespot-org/librespot/issues/1308#issuecomment-2276196094

Please provide the instructions on how to use Zeroconf instead of Session?

@pdtan you may use this very sketchy code to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session

Use .stored_file() method instead or .user_pass() on session builder stage to load login credentials from local file:

session = Session.Builder() \
    .stored_file() \
    .create()

It should use credentials.json from current working directory by default.

<!-- gh-comment-id:2291577767 --> @g42ftw commented on GitHub (Aug 15, 2024): **Login with username/password via `.user_pass()` method is no longer possible: https://github.com/librespot-org/librespot/issues/1308#issuecomment-2276196094** > Please provide the instructions on how to use Zeroconf instead of Session? @pdtan you may use [this very sketchy code](https://gist.github.com/g42ftw/b61304497cb19564e89f50197cf4d730) to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session Use `.stored_file()` method instead or `.user_pass()` on [session builder stage](https://github.com/kokarare1212/librespot-python?tab=readme-ov-file#get-spotifys-oauth-token) to load login credentials from local file: ```python session = Session.Builder() \ .stored_file() \ .create() ``` It should use `credentials.json` from current working directory by default.
Author
Owner

@clemwo commented on GitHub (Aug 15, 2024):

Login with username/password via .user_pass() method is no longer possible: librespot-org/librespot#1308 (comment)

Please provide the instructions on how to use Zeroconf instead of Session?

@pdtan you may use this very sketchy code to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session

Use .stored_file() method instead or .user_pass() on session builder stage to load login credentials from local file:

session = Session.Builder() \
    .stored_file() \
    .create()

It should use credentials.json from current working directory by default.

Cool beans, that works.

Question: do the credentials expire?
I want to run librespot in a docker container and maybe transfering playback once would be fine.
But if the token expired every few days that would be an issue for me.

<!-- gh-comment-id:2292053425 --> @clemwo commented on GitHub (Aug 15, 2024): > **Login with username/password via `.user_pass()` method is no longer possible: [librespot-org/librespot#1308 (comment)](https://github.com/librespot-org/librespot/issues/1308#issuecomment-2276196094)** > > > Please provide the instructions on how to use Zeroconf instead of Session? > > @pdtan you may use [this very sketchy code](https://gist.github.com/g42ftw/b61304497cb19564e89f50197cf4d730) to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session > > Use `.stored_file()` method instead or `.user_pass()` on [session builder stage](https://github.com/kokarare1212/librespot-python?tab=readme-ov-file#get-spotifys-oauth-token) to load login credentials from local file: > > ```python > session = Session.Builder() \ > .stored_file() \ > .create() > ``` > > It should use `credentials.json` from current working directory by default. Cool beans, that works. Question: do the credentials expire? I want to run librespot in a docker container and maybe transfering playback once would be fine. But if the token expired every few days that would be an issue for me.
Author
Owner

@kingosticks commented on GitHub (Aug 15, 2024):

Reusable credentials do not expire.

<!-- gh-comment-id:2292064875 --> @kingosticks commented on GitHub (Aug 15, 2024): Reusable credentials do not expire.
Author
Owner

@g42ftw commented on GitHub (Aug 15, 2024):

Question: do the credentials expire?

@clemwo they don't expire, unless you change your password or Spotify does. Successful login with zeroconf should always return the same long-live credentials that .user_pass always did (username+credentials blob).

The Spotify desktop client stores account login data in the client configuration file in a similar way:

.config/Spotify/prefs
autologin.blob="BLOB"
autologin.saved_credentials="{"USERNAME": ["USERNAME", "BLOB"]}"
<!-- gh-comment-id:2292138538 --> @g42ftw commented on GitHub (Aug 15, 2024): > Question: do the credentials expire? @clemwo they don't expire, unless you change your password or Spotify does. Successful login with zeroconf should always return the same long-live credentials that `.user_pass` always did (username+credentials blob). The Spotify desktop client stores account login data in the client configuration file in a similar way: <details> <summary>.config/Spotify/prefs</summary> ```ini autologin.blob="BLOB" autologin.saved_credentials="{"USERNAME": ["USERNAME", "BLOB"]}" ``` </details>
Author
Owner

@pdtan commented on GitHub (Aug 16, 2024):

@clemwo thanks, but I use credentials.json from start, sometimes BadCredentials still happended, not usual. If using zeroconf to only create credentials.json, I actually don't need it.

RuntimeError IN (test.py, LINE 141 "session = Session.Builder().stored_file().create()"): login_failed {
  error_code: BadCredentials
}
<!-- gh-comment-id:2292598882 --> @pdtan commented on GitHub (Aug 16, 2024): @clemwo thanks, but I use credentials.json from start, sometimes BadCredentials still happended, not usual. If using zeroconf to only create credentials.json, I actually don't need it. ``` RuntimeError IN (test.py, LINE 141 "session = Session.Builder().stored_file().create()"): login_failed { error_code: BadCredentials } ```
Author
Owner

@sertraline commented on GitHub (Aug 17, 2024):

On Windows (this works on Linux) trying to use zeroconf results in the following:

WARNING:zeroconf:Error with socket 696 (('0.0.0.0', 5353))): [WinError 87] The parameter is incorrect
Traceback (most recent call last):
  File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\proactor_events.py", line 577, in _loop_reading
    self._read_fut = self._loop._proactor.recvfrom(self._sock,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\windows_events.py", line 509, in recvfrom
    self._register_with_iocp(conn)
  File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\windows_events.py", line 709, in _register_with_iocp
    _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
OSError: [WinError 87] The parameter is incorrect
<!-- gh-comment-id:2294931466 --> @sertraline commented on GitHub (Aug 17, 2024): On Windows (this works on Linux) trying to use zeroconf results in the following: ``` WARNING:zeroconf:Error with socket 696 (('0.0.0.0', 5353))): [WinError 87] The parameter is incorrect Traceback (most recent call last): File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\proactor_events.py", line 577, in _loop_reading self._read_fut = self._loop._proactor.recvfrom(self._sock, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\windows_events.py", line 509, in recvfrom self._register_with_iocp(conn) File "C:\Users\sertraline\AppData\Local\Programs\Python\Python312\Lib\asyncio\windows_events.py", line 709, in _register_with_iocp _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0) OSError: [WinError 87] The parameter is incorrect ```
Author
Owner

@direct-dok commented on GitHub (Aug 22, 2024):

Hello everyone. Tell me if the librespot.core problem has been solved.Session.SpotifyAuthenticationException: BadCredentials
Can someone tell me what needs to be done? Thanks for any hints

<!-- gh-comment-id:2304490586 --> @direct-dok commented on GitHub (Aug 22, 2024): Hello everyone. Tell me if the librespot.core problem has been `solved.Session.SpotifyAuthenticationException: BadCredentials` Can someone tell me what needs to be done? Thanks for any hints
Author
Owner

@sertraline commented on GitHub (Aug 26, 2024):

I don't quite get how to generate the credentials. Quick glance at zeroconf.py tells me that I somehow need to get into handle_add_user to generate the credentials. I have tried to reopen the spotify client, log out and log in back but the add_user request just never happens, so I'm clueless on how to actually use it.

Zeroconf HTTP server started successfully on port 35710!
Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'}
Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'}
Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'}
Handling request: GET, /?action=getInfo&version=2.7.1, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'}
<!-- gh-comment-id:2310187046 --> @sertraline commented on GitHub (Aug 26, 2024): I don't quite get how to generate the credentials. Quick glance at zeroconf.py tells me that I somehow need to get into `handle_add_user` to generate the credentials. I have tried to reopen the spotify client, log out and log in back but the add_user request just never happens, so I'm clueless on how to actually use it. ``` Zeroconf HTTP server started successfully on port 35710! Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'} Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'} Handling request: GET, /?action=getInfo, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'} Handling request: GET, /?action=getInfo&version=2.7.1, HTTP/1.1, headers: {'Accept-Encoding': 'gzip', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded', 'Keep-Alive': '0', 'Host': '127.0.1.1', 'User-Agent': 'Spotify/124200000 Linux/0 (PC desktop)'} ```
Author
Owner

@kingosticks commented on GitHub (Aug 26, 2024):

Select the running librespot instance in your Spotify client. You should find it in the list of Spotify Connect devices in Spotify's client. That device menu is at the bottom of their app on the currently playing bar, it has a speaker/computer icon.

Selecting the librespot instance will send the required auth data to the Zeroconf server where it can be stored and reused indefinitely.

<!-- gh-comment-id:2310204655 --> @kingosticks commented on GitHub (Aug 26, 2024): Select the running librespot instance in your Spotify client. You should find it in the list of Spotify Connect devices in Spotify's client. That device menu is at the bottom of their app on the currently playing bar, it has a speaker/computer icon. Selecting the librespot instance will send the required auth data to the Zeroconf server where it can be stored and reused indefinitely.
Author
Owner

@clemwo commented on GitHub (Sep 15, 2024):

Login with username/password via .user_pass() method is no longer possible: librespot-org/librespot#1308 (comment)

Please provide the instructions on how to use Zeroconf instead of Session?

@pdtan you may use this very sketchy code to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session

Use .stored_file() method instead or .user_pass() on session builder stage to load login credentials from local file:

session = Session.Builder() \
    .stored_file() \
    .create()

It should use credentials.json from current working directory by default.

Unfortunately this code doesn't work when run in asyncio.

I get the following error:

  File "/Users/clemens/reps/carrotify/.venv/lib/python3.12/site-packages/zeroconf/_utils/asyncio.py", line 86, in run_coro_with_timeout
    return asyncio.run_coroutine_threadsafe(aw, loop).result(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 458, in result
    raise TimeoutError()
TimeoutError

Does anyone have an idea on how to adjust the code to make it run in async?

<!-- gh-comment-id:2351719508 --> @clemwo commented on GitHub (Sep 15, 2024): > **Login with username/password via `.user_pass()` method is no longer possible: [librespot-org/librespot#1308 (comment)](https://github.com/librespot-org/librespot/issues/1308#issuecomment-2276196094)** > > > Please provide the instructions on how to use Zeroconf instead of Session? > > @pdtan you may use [this very sketchy code](https://gist.github.com/g42ftw/b61304497cb19564e89f50197cf4d730) to generate credentials file to use further. Notice that device running the script should be on the same network as a desktop client in order to transfer playback or/and grab session > > Use `.stored_file()` method instead or `.user_pass()` on [session builder stage](https://github.com/kokarare1212/librespot-python?tab=readme-ov-file#get-spotifys-oauth-token) to load login credentials from local file: > > ```python > session = Session.Builder() \ > .stored_file() \ > .create() > ``` > > It should use `credentials.json` from current working directory by default. Unfortunately this code doesn't work when run in asyncio. I get the following error: ```Traceback (most recent call last): File "/Users/clemens/reps/carrotify/.venv/lib/python3.12/site-packages/zeroconf/_utils/asyncio.py", line 86, in run_coro_with_timeout return asyncio.run_coroutine_threadsafe(aw, loop).result( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 458, in result raise TimeoutError() TimeoutError ``` Does anyone have an idea on how to adjust the code to make it run in async?
Author
Owner

@shuttie commented on GitHub (Sep 16, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

<!-- gh-comment-id:2352123043 --> @shuttie commented on GitHub (Sep 16, 2024): This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth
Author
Owner

@greffgreff commented on GitHub (Nov 22, 2024):

I can confirm that username and password is still possible with mobile authentication shenanigans. I am to get an access token and interact with spotify's api with librespot-js: https://git.gay/h/librespot-js/src/branch/main/src/login5.ts

<!-- gh-comment-id:2493991379 --> @greffgreff commented on GitHub (Nov 22, 2024): I can confirm that username and password is still possible with mobile authentication shenanigans. I am to get an access token and interact with spotify's api with `librespot-js`: https://git.gay/h/librespot-js/src/branch/main/src/login5.ts
Author
Owner

@jakiepari commented on GitHub (Dec 20, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

<!-- gh-comment-id:2556779420 --> @jakiepari commented on GitHub (Dec 20, 2024): > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth i'm using that tool and finally grabbed the credentials.json. but i try with this my code ``` from librespot.core import Session from librespot.metadata import TrackId from librespot.audio.decoders import AudioQuality import os try: session = Session.Builder().stored_file("./credentials.json").create() except Exception as e: print(f"Error creating session: {e}") print("Credentials not found or invalid. Please run the credentials.json creation script first.") exit(1) try: track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) audio_stream = track.input_stream except Exception as e: print(f"Error loading track: {e}") ``` its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D
Author
Owner

@moejoe95 commented on GitHub (Dec 26, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

<!-- gh-comment-id:2562947919 --> @moejoe95 commented on GitHub (Dec 26, 2024): > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > ``` > from librespot.core import Session > from librespot.metadata import TrackId > from librespot.audio.decoders import AudioQuality > import os > > try: > session = Session.Builder().stored_file("./credentials.json").create() > except Exception as e: > print(f"Error creating session: {e}") > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > exit(1) > > try: > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > audio_stream = track.input_stream > except Exception as e: > print(f"Error loading track: {e}") > ``` > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me.
Author
Owner

@jakiepari commented on GitHub (Dec 27, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution

<!-- gh-comment-id:2563705844 --> @jakiepari commented on GitHub (Dec 27, 2024): > > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > > > > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > ``` > > from librespot.core import Session > > from librespot.metadata import TrackId > > from librespot.audio.decoders import AudioQuality > > import os > > > > try: > > session = Session.Builder().stored_file("./credentials.json").create() > > except Exception as e: > > print(f"Error creating session: {e}") > > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > > exit(1) > > > > try: > > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > > audio_stream = track.input_stream > > except Exception as e: > > print(f"Error loading track: {e}") > > ``` > > > > > > > > > > > > > > > > > > > > > > > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D > > Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me. I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution
Author
Owner

@moejoe95 commented on GitHub (Dec 27, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution

Should be a Enum value as defined here. I used AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS.

<!-- gh-comment-id:2563710284 --> @moejoe95 commented on GitHub (Dec 27, 2024): > > > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > > > > > > > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > > ``` > > > from librespot.core import Session > > > from librespot.metadata import TrackId > > > from librespot.audio.decoders import AudioQuality > > > import os > > > > > > try: > > > session = Session.Builder().stored_file("./credentials.json").create() > > > except Exception as e: > > > print(f"Error creating session: {e}") > > > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > > > exit(1) > > > > > > try: > > > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > > > audio_stream = track.input_stream > > > except Exception as e: > > > print(f"Error loading track: {e}") > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D > > > > > > Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me. > > I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution Should be a Enum value as defined [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/proto/Authentication_pb2.py#L24). I used `AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS`.
Author
Owner

@jakiepari commented on GitHub (Dec 27, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution

Should be a Enum value as defined here. I used AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS.

for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value?

<!-- gh-comment-id:2563714558 --> @jakiepari commented on GitHub (Dec 27, 2024): > > > > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > > > > > > > > > > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > > > ``` > > > > from librespot.core import Session > > > > from librespot.metadata import TrackId > > > > from librespot.audio.decoders import AudioQuality > > > > import os > > > > > > > > try: > > > > session = Session.Builder().stored_file("./credentials.json").create() > > > > except Exception as e: > > > > print(f"Error creating session: {e}") > > > > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > > > > exit(1) > > > > > > > > try: > > > > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > > > > audio_stream = track.input_stream > > > > except Exception as e: > > > > print(f"Error loading track: {e}") > > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D > > > > > > > > > Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me. > > > > > > I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution > > Should be a Enum value as defined [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/proto/Authentication_pb2.py#L24). I used `AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS`. for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value?
Author
Owner

@moejoe95 commented on GitHub (Dec 27, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution

Should be a Enum value as defined here. I used AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS.

for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value?

use it like this: "type":"AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS"

<!-- gh-comment-id:2563717137 --> @moejoe95 commented on GitHub (Dec 27, 2024): > > > > > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > > > > > > > > > > > > > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > > > > ``` > > > > > from librespot.core import Session > > > > > from librespot.metadata import TrackId > > > > > from librespot.audio.decoders import AudioQuality > > > > > import os > > > > > > > > > > try: > > > > > session = Session.Builder().stored_file("./credentials.json").create() > > > > > except Exception as e: > > > > > print(f"Error creating session: {e}") > > > > > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > > > > > exit(1) > > > > > > > > > > try: > > > > > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > > > > > audio_stream = track.input_stream > > > > > except Exception as e: > > > > > print(f"Error loading track: {e}") > > > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D > > > > > > > > > > > > Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me. > > > > > > > > > I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution > > > > > > Should be a Enum value as defined [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/proto/Authentication_pb2.py#L24). I used `AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS`. > > for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value? use it like this: `"type":"AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS"`
Author
Owner

@jakiepari commented on GitHub (Dec 27, 2024):

This tool helped me to generate the credentials.json: https://github.com/dspearson/librespot-auth

i'm using that tool and finally grabbed the credentials.json. but i try with this my code

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality
import os

try:
    session = Session.Builder().stored_file("./credentials.json").create()
except Exception as e:
    print(f"Error creating session: {e}")
    print("Credentials not found or invalid. Please run the credentials.json creation script first.")
    exit(1)

try:
    track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None)
    audio_stream = track.input_stream
except Exception as e:
    print(f"Error loading track: {e}")

its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D

Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains type, username, credentials, see here. However, in the file i got from librespot-auth the fields are named auth_type and auth_data. Renaming the fields in the file fixed the issue for me.

I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution

Should be a Enum value as defined here. I used AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS.

for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value?

use it like this: "type":"AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS"

this is worked! Thank you very much!

<!-- gh-comment-id:2563721101 --> @jakiepari commented on GitHub (Dec 27, 2024): > > > > > > > This tool helped me to generate the `credentials.json`: https://github.com/dspearson/librespot-auth > > > > > > > > > > > > > > > > > > i'm using that tool and finally grabbed the credentials.json. but i try with this my code > > > > > > ``` > > > > > > from librespot.core import Session > > > > > > from librespot.metadata import TrackId > > > > > > from librespot.audio.decoders import AudioQuality > > > > > > import os > > > > > > > > > > > > try: > > > > > > session = Session.Builder().stored_file("./credentials.json").create() > > > > > > except Exception as e: > > > > > > print(f"Error creating session: {e}") > > > > > > print("Credentials not found or invalid. Please run the credentials.json creation script first.") > > > > > > exit(1) > > > > > > > > > > > > try: > > > > > > track = session.content_feeder().load(TrackId.from_uri("spotify:track:7KA4W4McWYRpgf0fWsJZWB"), AudioQuality.HIGH, False, None) > > > > > > audio_stream = track.input_stream > > > > > > except Exception as e: > > > > > > print(f"Error loading track: {e}") > > > > > > ``` > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > its always giving: Error creating session: You must select an authentication method. how to use credentials.json? thank you :D > > > > > > > > > > > > > > > Got the same error. Looks like the credential file has changed its format. In the source code it is expected that the json contains `type`, `username`, `credentials`, see [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/core.py#L1588). However, in the file i got from [librespot-auth](https://github.com/dspearson/librespot-auth) the fields are named `auth_type` and `auth_data`. Renaming the fields in the file fixed the issue for me. > > > > > > > > > > > > I'm trying to rename it. but what should i fill in the type? :D btw thank you for this solution > > > > > > > > > Should be a Enum value as defined [here](https://github.com/kokarare1212/librespot-python/blob/main/librespot/proto/Authentication_pb2.py#L24). I used `AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS`. > > > > > > for example i try with this format: {"type":1,"username":"numberi","credentials":"string"}. and i try to use enum value defined 1 and its giving error: Error: Enum AuthenticationType has no value defined for name 1. how to use the value? > > use it like this: `"type":"AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS"` this is worked! Thank you very much!
Author
Owner

@root4loot commented on GitHub (Sep 30, 2025):

Same issue with username/password auth. As a workaround, I got it to work with OAuth credentials from Rust librespot.

See pull #314 which adds support for this in stored_file().

<!-- gh-comment-id:3353047850 --> @root4loot commented on GitHub (Sep 30, 2025): Same issue with username/password auth. As a workaround, I got it to work with OAuth credentials from Rust librespot. See pull #314 which adds support for this in stored_file().
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot-python-kokarare1212#51
No description provided.