mirror of
https://github.com/kokarare1212/librespot-python.git
synced 2026-04-25 16:45:50 +03:00
[GH-ISSUE #306] [BUG] Error in TOKEN Authentication #53
Labels
No labels
bug
dependencies
duplicate
enhancement
invalid
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/librespot-python-kokarare1212#53
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @matteofuso on GitHub (Jun 14, 2025).
Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/306
Describe the bug
When i try to log in with the new oauth, the new credentials.json is dumped and then an exeption stop the code execution. If I try to re-run, the login process works with the stored credentials
To Reproduce
Run the snippet provided in the readme
from librespot.core import Session
def auth_url_callback(url):
print(url)
session = Session.Builder()
.oauth(auth_url_callback)
.create()
Expected behavior
It should log in without an exeption
Client Information (please complete the following information):
Additional context
The exception
Traceback (most recent call last):
File "c:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader\a.py", line 10, in
.create()
^^^^^^^^
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 1647, in create
session.authenticate(self.login_credentials)
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 955, in authenticate
self.dealer().connect()
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 451, in connect
self.__session.tokens().get("playlist-read"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 2251, in get
return self.get_token(scope).access_token
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 2271, in get_token
response = self._session.mercury().send_sync_json(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\matteo\OneDrive - elFusoo\Desktop\Scrivania\Programmazione\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\mercury.py", line 186, in send_sync_json
raise MercuryClient.MercuryException(response)
librespot.mercury.MercuryClient.MercuryException: status: 403
@matteofuso commented on GitHub (Aug 7, 2025):
After further investigation, the error seems to come from Token authentication. I've tried to fix the error but I'm not familiar with it and I didn't want to mess the codebase. Here what I've tested and found
CODE:
2025-08-07 11:15:34,638 DEBUG urllib3.connectionpool [connectionpool.py:1049 _new_conn] Starting new HTTPS connection (1): apresolve.spotify.com:443
2025-08-07 11:15:34,706 DEBUG urllib3.connectionpool [connectionpool.py:544 _make_request] https://apresolve.spotify.com:443 "GET /?type=accesspoint HTTP/1.1" 200 None
2025-08-07 11:15:34,839 INFO Librespot:Session [core.py:908 init] Created new session! device_id: ee10963a630a0da9d3fcfbf8adf6fb8c91314af0, ap: ap-gue1.spotify.com:4070
2025-08-07 11:15:36,024 INFO Librespot:Session [core.py:1107 connect] Connection successfully!
2025-08-07 11:15:36,194 INFO Librespot:Session [core.py:1998 run] Session.Receiver started
2025-08-07 11:15:36,196 DEBUG urllib3.connectionpool [connectionpool.py:1049 _new_conn] Starting new HTTPS connection (1): apresolve.spotify.com:443
2025-08-07 11:15:36,286 DEBUG urllib3.connectionpool [connectionpool.py:544 _make_request] https://apresolve.spotify.com:443 "GET /?type=spclient HTTP/1.1" 200 None
2025-08-07 11:15:36,288 INFO Librespot:Session [core.py:2072 run] Skipping 02
2025-08-07 11:15:36,288 INFO Librespot:Session [core.py:2051 run] Received license_version: 0
2025-08-07 11:15:36,289 DEBUG urllib3.connectionpool [connectionpool.py:1049 _new_conn] Starting new HTTPS connection (1): apresolve.spotify.com:443
2025-08-07 11:15:36,289 INFO Librespot:Session [core.py:2038 run] Received country_code: IT
2025-08-07 11:15:36,299 DEBUG Librespot:Session [core.py:1210 parse_product_info] Parsed product info: {'type': 'free', 'ab-ad-player-targeting': '1', 'ab-watch-now': '0', 'ab_recently_played_feature_time_filter_threshold': 'com.spotify.gaia=30,driving-mode=120,spotify%3Ainternal%3Astartpage=30', 'ad-formats-preroll-video': '0', 'ad-session-persistence': '1', 'ads': '1', 'app-developer': '0', 'arsenal_country': '1', 'audio-preview-url-template': 'https://p.scdn.co/mp3-preview/{id}', 'audio-quality': '0', 'audiobook-onboarding-completed': '0', 'audiobook-onboarding-dismissed': '0', 'autoplay': '1', 'browse-overview-enabled': '1', 'buffering-strategy-parameters': '0.8:0.2:0.0:0.0:0.0:0.0:1.0:10:10:2000:10000:10485760', 'capper-profile': None, 'capping-bar-threshold': '3601', 'catalogue': 'free', 'client-deprecated': '1', 'collection': '1', 'created_by_partner': None, 'employee-free-opt-in': '0', 'enable-annotations': '2', 'enable-annotations-read': '0', 'enable-crossfade': '1', 'explicit-content': '1', 'fb-grant-permission-local-render': '0', 'fb-info-confirmation': 'control', 'filter-explicit-content': '0', 'financial-product': 'pr:free,tc:0', 'head-file-caching': '1', 'head-files': '1', 'head-files-url': 'https://heads-fa-tls13.spotifycdn.com/head/{file_id}', 'high-bitrate': '0', 'image-url': 'https://i.scdn.co/image/{file_id}', 'incognito_mode_timeout': '21600', 'is_email_verified': '1', 'key-caching-auto-offline': '0', 'key-caching-max-count': '10000', 'key-caching-max-offline-seconds': '1800', 'key-memory-cache-mode': '1:15,300', 'libspotify': '0', 'license-acceptance-grace-days': '0', 'license-agreements': None, 'metadata-link-lookup-modes': '0', 'mobile': '0', 'mobile-browse': '0', 'mobile-login': '0', 'mobile-payment': '0', 'name': 'Spotify Free', 'network-operator-premium-activation': '1', 'nft-disabled': '1', 'offline': '0', 'on-demand': '1', 'on-demand-trial-in-progress': '0', 'payment-state': None, 'payments-locked-state': '0', 'player-license': 'on-demand', 'player-license-v2': 'on-demand', 'playlist-annotations-markup': '0', 'preferred-locale': 'en', 'prefetch-keys': '1', 'prefetch-strategy': '18', 'prefetch-window-max': '2', 'publish-activity': '0', 'publish-playlist': '0', 'radio': '1', 'rating-access': '1', 'remote-control': '6', 'restrict-playlist-collaboration': '0', 'send-email': '0', 'shows-collection': '1', 'shows-collection-jam': '0', 'shuffle': '0', 'shuffle-algorithm': 'RANDOM', 'sidebar-navigation-enabled': '0', 'storage-size-config': '10240,90,500,3', 'streaming': '1', 'streaming-rules': None, 'track-cap': '0', 'ugc-abuse-report': '1', 'ugc-abuse-report-url': 'https://support.spotify.com/abuse/?uri={uri}', 'use-fb-publish-backend': '2', 'user-profile-show-invitation-codes': '0', 'video-cdn-sampling': '100', 'video-device-blacklisted': '0', 'video-initial-bitrate': '200000', 'video-keyframe-url': 'http://keyframes-fa.cdn.spotify.com/keyframes/v1/sources/{source_id}/keyframe/heights/{height}/timestamps/{timestamp_ms}.jpg', 'video-manifest-url': 'https://spclient.wg.spotify.com/manifests/v6/{type}/sources/{source_id}/options/supports_drm', 'video-wifi-initial-bitrate': '800000', 'widevine-license-url': 'https://spclient.wg.spotify.com/widevine-license/v1/video/license'}
2025-08-07 11:15:36,299 INFO Librespot:Session [core.py:2072 run] Skipping 1f
2025-08-07 11:15:36,299 INFO Librespot:Session [core.py:2072 run] Skipping 69
2025-08-07 11:15:36,311 DEBUG Librespot:MercuryClient [mercury.py:72 dispatch] Handling packet, cmd: 0xb5, seq: -5070953124861050880, flags: b'\x01', parts: 1
2025-08-07 11:15:36,312 DEBUG Librespot:MercuryClient [mercury.py:94 dispatch] Couldn't dispatch Mercury event seq: -5070953124861050880, uri: hm://pusher/v1/connections/ZWUxMDk2M2E2MzBhMGRhOWQzZmNmYmY4YWRmNmZiOGM5MTMxNGFmMCtBUCt0Y3A6Ly8wYWIxNDE1Ny5pcC5ndWUxLnNwb3RpZnkubmV0OjUwMDArQUY1OUFDMDBEQzM0ODU1OEREOTQwMTI3MTgwNEVCMDk2QkExQ0ZDRDY4RUZEMTA2OUZDMTBEQUNCRDJGMzM3Qg%3D%3D, code: 200, payload: b''
2025-08-07 11:15:36,360 DEBUG urllib3.connectionpool [connectionpool.py:544 _make_request] https://apresolve.spotify.com:443 "GET /?type=dealer HTTP/1.1" 200 None
2025-08-07 11:15:36,360 DEBUG Librespot:TokenProvider [core.py:2268 get_token] Token expired or not suitable, requesting again. scopes: ['playlist-read'], old_token: None
2025-08-07 11:15:36,361 DEBUG Librespot:MercuryClient [mercury.py:143 send] Send Mercury request, seq: 0, uri: hm://keymaster/token/authenticated?scope=playlist-read&client_id=65b708073fc0480ea92a077233ca87bd&device_id=ee10963a630a0da9d3fcfbf8adf6fb8c91314af0, method: GET
2025-08-07 11:15:36,425 DEBUG Librespot:Session [core.py:2054 run] Received 0x10: 5252c43f44a28e12326311588ed0bb4c855efc16
2025-08-07 11:15:36,707 DEBUG Librespot:MercuryClient [mercury.py:72 dispatch] Handling packet, cmd: 0xb2, seq: 0, flags: b'\x01', parts: 2
Traceback (most recent call last):
2025-08-07 11:15:36,708 INFO Librespot:Session [core.py:2007 run] Skipping unknown command cmd: 0x75, payload: b'\x00\x00\x01'
File "d:\Linguaggi\Python\musicdownloader\session.py", line 38, in
session = session.create()
^^^^^^^^^^^^^^^^
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 1647, in create
session.authenticate(self.login_credentials)
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 955, in authenticate
self.dealer().connect()
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 451, in connect
self.__session.tokens().get("playlist-read"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 2251, in get
return self.get_token(scope).access_token
^^^^^^^^^^^^^^^^^^^^^
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\core.py", line 2271, in get_token
response = self._session.mercury().send_sync_json(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Linguaggi\Python\musicdownloader.musicdownloader\Lib\site-packages\librespot\mercury.py", line 186, in send_sync_json
raise MercuryClient.MercuryException(response)
librespot.mercury.MercuryClient.MercuryException: status: 403
@IsaacAgulhas commented on GitHub (Aug 12, 2025):
having the same issue, it seems spotify has made changes to their system that is breaking this library
@Dec-QXY commented on GitHub (Aug 13, 2025):
Do you have a new solution now?
@gaspard11 commented on GitHub (Aug 13, 2025):
Hi,
I am getting the same issue on my end.
The problem seems to happen on all distributions and projects using librespot (e.g https://github.com/librespot-org/librespot/issues/1532).
Using Login5 seems to be menionned as a solution but I don't know how to implement that
@463563466 commented on GitHub (Aug 14, 2025):
Hi,
I am getting the same issue on my end.
Is the 403 problem solved?
@gaspard11 commented on GitHub (Aug 14, 2025):
Hello,
This commit on the spotizerr repo proposes a solution to replace mercury by login5 in the python distribution :
https://github.com/Xoconoch/librespot-spotizerr/pull/6
might be worth checking
@Cybernatus commented on GitHub (Aug 14, 2025):
Can confirm that manually applying the changes from the remote patch above on librespot-python fixes the issue.