[GH-ISSUE #154] [BUG] Audio key error when switching to very high quality #23

Closed
opened 2026-02-27 08:11:29 +03:00 by kerem · 4 comments
Owner

Originally created by @mponweiser on GitHub (Sep 16, 2022).
Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/154

Describe the bug
Hi @kokarare1212, I am following the example "Get Music Stream", and depending on the AudioQuality flag, I am getting a RuntimeError:

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality

from librespot import Version
Version.system_info_string()
# 'librespot-python 0.0.6; Python 3.10.4; Linux'


# family (=premium) account
session = Session.Builder() \
    .user_pass("XXX", "XXX") \
    .create()

track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD")
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)

Error message:

Audio key error, code: 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 722, in load
    return self.load_track(playable_id, audio_quality_picker, preload,
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 783, in load_track
    return self.load_stream(file, track, None, preload, halt_listener)
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 737, in load_stream
    return CdnFeedHelper.load_track(self.__session, track, file,
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 336, in load_track
    key = session.audio_key().get_audio_key(track.gid, file.file_id)
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 277, in get_audio_key
    return self.get_audio_key(gid, file_id, False)
  File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 278, in get_audio_key
    raise RuntimeError(
RuntimeError: Failed fetching audio key! gid: XXX, fileId: XXX

I am very certain I have a family account and in the desktop app on Linux can stream on HQ, so I don't see how this error can happen.
Would you be willing to look into this?

Originally created by @mponweiser on GitHub (Sep 16, 2022). Original GitHub issue: https://github.com/kokarare1212/librespot-python/issues/154 **Describe the bug** Hi @kokarare1212, I am following the example "Get Music Stream", and depending on the AudioQuality flag, I am getting a RuntimeError: ``` from librespot.core import Session from librespot.metadata import TrackId from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality from librespot import Version Version.system_info_string() # 'librespot-python 0.0.6; Python 3.10.4; Linux' # family (=premium) account session = Session.Builder() \ .user_pass("XXX", "XXX") \ .create() track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD") stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None) ``` Error message: ``` Audio key error, code: 1 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 722, in load return self.load_track(playable_id, audio_quality_picker, preload, File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 783, in load_track return self.load_stream(file, track, None, preload, halt_listener) File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 737, in load_stream return CdnFeedHelper.load_track(self.__session, track, file, File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 336, in load_track key = session.audio_key().get_audio_key(track.gid, file.file_id) File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 277, in get_audio_key return self.get_audio_key(gid, file_id, False) File "/home/mpon/.local/lib/python3.10/site-packages/librespot/audio/__init__.py", line 278, in get_audio_key raise RuntimeError( RuntimeError: Failed fetching audio key! gid: XXX, fileId: XXX ``` I am very certain I have a family account and in the desktop app on Linux can stream on HQ, so I don't see how this error can happen. Would you be willing to look into this?
kerem 2026-02-27 08:11:29 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kokarare1212 commented on GitHub (Sep 16, 2022):

Generally, such errors are caused by codecs that are not supported, account issues that prevent playback at the highest audio quality, or music that does not support the highest audio quality.
Can you tell me the Spotify URI where the problem occurs?

<!-- gh-comment-id:1249910583 --> @kokarare1212 commented on GitHub (Sep 16, 2022): Generally, such errors are caused by codecs that are not supported, account issues that prevent playback at the highest audio quality, or music that does not support the highest audio quality. Can you tell me the Spotify URI where the problem occurs?
Author
Owner

@mponweiser commented on GitHub (Sep 17, 2022):

Thank you, this makes it a bit easier to understand what might be the problem.
However, what are "account issues"? Is Spotify selectively disabling HQ playback on their side, even for premium users?

As to your question: the song ID is in the bug report, but others are causing the same problem:

track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD")
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
<!-- gh-comment-id:1250025571 --> @mponweiser commented on GitHub (Sep 17, 2022): Thank you, this makes it a bit easier to understand what might be the problem. However, what are "account issues"? Is Spotify selectively disabling HQ playback on their side, even for premium users? As to your question: the song ID is in the bug report, but others are causing the same problem: ``` track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD") stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None) ```
Author
Owner

@kokarare1212 commented on GitHub (Sep 17, 2022):

Strangely enough, it worked fine when I tried it.
I think the possible cause is that the songs do not correspond to the region of the account.

from librespot.audio.decoders import VorbisOnlyAudioQuality, AudioQuality
from librespot.core import Session
from librespot.metadata import TrackId
import logging


logging.basicConfig(level=logging.DEBUG)
session = Session.Builder().stored().create()
track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD")
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
stream.input_stream.stream().read()

<!-- gh-comment-id:1250030559 --> @kokarare1212 commented on GitHub (Sep 17, 2022): Strangely enough, it worked fine when I tried it. I think the possible cause is that the songs do not correspond to the region of the account. ```python from librespot.audio.decoders import VorbisOnlyAudioQuality, AudioQuality from librespot.core import Session from librespot.metadata import TrackId import logging logging.basicConfig(level=logging.DEBUG) session = Session.Builder().stored().create() track_id = TrackId.from_uri("spotify:track:2o4MCgSayrqYirCNfbx0jD") stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None) stream.input_stream.stream().read() ```
Author
Owner

@mponweiser commented on GitHub (Sep 17, 2022):

OK, so I re-checked everything and it seems I was using an old - free - account, so the error was to be expected.
Thanks a lot you for your attention and patience, and of course, your work :-)

<!-- gh-comment-id:1250036943 --> @mponweiser commented on GitHub (Sep 17, 2022): OK, so I re-checked everything and it seems I was using an old - free - account, so the error was to be expected. Thanks a lot you for your attention and patience, and of course, your work :-)
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#23
No description provided.