Mopidy-Spotify - Can browse, but can't add tracks

Running on Raspberry Pi 4, with Iris. Local music play works fine, and I can browse to Spotify tracks and albums, however I get “Mopidy: Failed to add some tracks” when I try to play Spotify songs. I have reauthenticated recently. I’m a little confused by the logs. One part says that it is unable to contact server, but then it does say successfully logged into the API later.

Here’s some logs after restarting Mopidy and then attempting to load tracks:

Mar 05 13:03:33 raspberrypi mopidy[11620]: ERROR    [SpotifyEventLoop] spotify.session Spotify login error: <ErrorType.UNABLE_TO_CONTACT_SERVER: 8>
Mar 05 13:03:34 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.web Logged into Spotify Web API as holy.zarquon
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.playlists Refreshed 24 Spotify playlists
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [MainThread] mopidy.commands Starting Mopidy core
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [MainThread] mopidy.commands Starting Mopidy frontends: YouTubeAutoplayer, IrisFrontend, HttpFrontend
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [IrisFrontend-16] mopidy_iris.core Starting Iris 3.60.1
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [HttpFrontend-18] mopidy.http.actor HTTP server running at [::ffff:0.0.0.0]:6680
Mar 05 13:03:56 raspberrypi mopidy[11620]: INFO     [MainThread] mopidy.commands Starting GLib mainloop
Mar 05 13:03:59 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:album:0L5uOzFpdnqCTWgGfUQmQ0': Session must be logged in and online to load obj
Mar 05 13:09:06 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:46Nz7uguhTyUWOXhRBbzxa': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:46Nz7uguhTyUWOXhRBbzxa': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:2yB0oBqoZRXehgynGISA5J': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:2nDqDJ5sEbFMSNodxXxgJL': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:0Plf9mewMoYkwEvncCjfxS': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:2XpYbNac0WKvEMbyEy6qeW': Session must be logged in and online to load obj
Mar 05 13:09:09 raspberrypi mopidy[11620]: INFO     [SpotifyBackend-4] mopidy_spotify.lookup Failed to lookup 'spotify:track:3cDluEFBvGZKCHqO00aY73': Session must be logged in and online to load obj

Configuration output:

Running "/usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf config" as user mopidy
[core]
cache_dir = /var/cache/mopidy
config_dir = /etc/mopidy
data_dir = /var/lib/mopidy
max_tracklist_length = 10000
restore_state = false

[logging]
verbosity = 0
format = %(levelname)-8s [%(threadName)s] %(name)s %(message)s
color = false
config_file =

[audio]
mixer = software
mixer_volume = 
output = audioresample ! audioconvert ! audio/x-raw,rate=48000,channels=2,format=S16LE ! wavenc ! filesink location=/tmp/snapfifo
buffer_time = 

[proxy]
scheme = 
hostname = 
port = 
username = 
password = 

[youtube]
enabled = true
youtube_api_key = 
threads_max = 16
search_results = 15
playlist_max_videos = 20
api_enabled = false
autoplay_enabled = false
strict_autoplay = false
max_autoplay_length = 600
max_degrees_of_separation = 3

[spotify]
enabled = true
username = bopot427@gmail.com
password = ********
client_id = 47d3c055-7c60-4d0a-984e-0bc59d73d6d0
client_secret = ********
bitrate = 160
volume_normalization = true
private_session = false
timeout = 10
allow_cache = true
allow_network = true
allow_playlists = true
search_album_count = 20
search_artist_count = 10
search_track_count = 50
toplist_countries = 

[podcast]
enabled = true
browse_root = /mnt/raid1/NAS Share Pi/Music
browse_order = desc
lookup_order = asc
cache_size = 64
cache_ttl = 86400
timeout = 10

[local]
enabled = true
max_search_results = 100
media_dir = /mnt/raid1/NAS Share Pi/Music
scan_timeout = 1000
scan_flush_threshold = 100
scan_follow_symlinks = false
included_file_extensions = 
excluded_file_extensions = 
  .cue
  .directory
  .html
  .jpeg
  .jpg
  .log
  .nfo
  .pdf
  .png
  .txt
  .zip
directories = 
  Albums                  local:directory?type=album
  Artists                 local:directory?type=artist
  Composers               local:directory?type=artist&role=composer
  Genres                  local:directory?type=genre
  Performers              local:directory?type=artist&role=performer
  Release Years           local:directory?type=date&format=%25Y
  Tracks                  local:directory?type=track
  Last Week's Updates     local:directory?max-age=604800
  Last Month's Updates    local:directory?max-age=2592000
timeout = 10
use_artist_sortname = false
album_art_files = 
  *.jpg
  *.jpeg
  *.png

[iris]
enabled = true
country = US
locale = en_US
snapcast_enabled = true
snapcast_host = localhost
snapcast_port = 1780
snapcast_ssl = false
snapcast_stream = Default
spotify_authorization_url = https://jamesbarnsley.co.nz/iris/auth_spotify.php
lastfm_authorization_url = https://jamesbarnsley.co.nz/iris/auth_lastfm.php
genius_authorization_url = https://jamesbarnsley.co.nz/iris/auth_genius.php
data_dir = $XDG_DATA_DIR/iris

[file]
enabled = true
media_dirs = 
  $XDG_MUSIC_DIR|Music
  ~/|Home
excluded_file_extensions = 
  .directory
  .html
  .jpeg
  .jpg
  .log
  .nfo
  .pdf
  .png
  .txt
  .zip
show_dotfiles = false
follow_symlinks = false
metadata_timeout = 1000

[http]
enabled = true
hostname = 0.0.0.0
port = 6680
zeroconf = Mopidy HTTP server on $hostname
allowed_origins = 
csrf_protection = true
default_app = mopidy

[m3u]
enabled = true
base_dir =
default_encoding = latin-1
default_extension = .m3u8
playlists_dir =

[softwaremixer]
enabled = true

[stream]
enabled = true
protocols = 
  http
  https
  mms
  rtmp
  rtmps
  rtsp
metadata_blacklist = 
timeout = 5000

[tunein]
enabled = true
timeout = 5000
filter = 

[podcast-itunes]
enabled = true
base_url = http://itunes.apple.com/
country = US
explicit = 
charts = audioPodcasts
charts_limit = 20
search_limit = 20
timeout = 10
retries = 3

Deps output

Running "/usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf deps" as user mopidy
Executable: /usr/bin/mopidy
Platform: Linux-5.10.11-v7l+-armv7l-with-debian-10.11
Python: CPython 3.7.3 from /usr/lib/python3.7
Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
Mopidy-YouTube: 3.2 from /usr/local/lib/python3.7/dist-packages
  requests: 2.21.0 from /usr/lib/python3/dist-packages
  cachetools: 4.2.1 from /usr/local/lib/python3.7/dist-packages
  Pykka: 2.0.3 from /usr/lib/python3/dist-packages
  youtube-dl: 2021.2.10 from /usr/local/lib/python3.7/dist-packages
  setuptools: 40.8.0 from /usr/lib/python3/dist-packages
  Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
  beautifulsoup4: 4.7.1 from /usr/lib/python3/dist-packages
Mopidy-Local: 3.2.0 from /usr/local/lib/python3.7/dist-packages
  setuptools: 40.8.0 from /usr/lib/python3/dist-packages
  uritools: 3.0.0 from /usr/local/lib/python3.7/dist-packages
  Pykka: 2.0.3 from /usr/lib/python3/dist-packages
  Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
Mopidy-Podcast-iTunes: 3.0.0 from /usr/lib/python3/dist-packages
Mopidy-Iris: 3.60.1 from /usr/local/lib/python3.7/dist-packages
  setuptools: 40.8.0 from /usr/lib/python3/dist-packages
  Pykka: 2.0.3 from /usr/lib/python3/dist-packages
  Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
Mopidy-TuneIn: 1.1.0 from /usr/lib/python3/dist-packages
Mopidy-Spotify: 4.1.1 from /usr/local/lib/python3.7/dist-packages
  pyspotify: 2.1.3 from /usr/lib/python3/dist-packages
  requests: 2.21.0 from /usr/lib/python3/dist-packages
  Pykka: 2.0.3 from /usr/lib/python3/dist-packages
  setuptools: 40.8.0 from /usr/lib/python3/dist-packages
  Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
Mopidy-Podcast: 3.0.0 from /usr/local/lib/python3.7/dist-packages
  cachetools: 4.2.1 from /usr/local/lib/python3.7/dist-packages
  Pykka: 2.0.3 from /usr/lib/python3/dist-packages
  setuptools: 40.8.0 from /usr/lib/python3/dist-packages
  uritools: 3.0.0 from /usr/local/lib/python3.7/dist-packages
  Mopidy: 3.2.0 from /usr/lib/python3/dist-packages
GStreamer: 1.14.4.0 from /usr/lib/python3/dist-packages/gi
  Detailed information: 
    Python wrapper: python-gi 3.30.4
    Relevant elements:
      Found:
        uridecodebin
        souphttpsrc
        appsrc
        alsasink
        osssink
        oss4sink
        pulsesink
        id3demux
        id3v2mux
        lamemp3enc
        mpegaudioparse
        mpg123audiodec
        vorbisdec
        vorbisenc
        vorbisparse
        oggdemux
        oggmux
        oggparse
        flacdec
        flacparse
        shout2send
      Not found:
        flump3dec
        mad

There are two parts to Mopidy-Spotify.

  1. libspotify: provides playback + lookup (and few other things). Requires premium account. Auths with your username + password
  2. Spotify Web APi: provides everything else. Auths with client id and secret.

Your log shows libspotify login is unable to contact the server (which is different to the Web API server). If I remember correctly, libspotify uses https://apresolve.spotify.com/ to get a list of nearby servers it can use. Sometimes some of those servers have issues - perhaps this is another case of that. I’ve heard from elsewhere that ap-gew4.spotify.com is currently broken but usually Spotify resolve these issues after a while. Or you could try forcing it to use a specific server by setting an entry in your /etc/hosts file like:

104.199.65.124  ap-gew4.spotify.com

Where 104.199.65.124 is the IP of one of the other access points that were provided to you from apresolve.spotify.com

Or you have some kind of firewall in place?

Here’s the full conversation about the hostname workaround.

1 Like

Yeh, thanks. It’s ap.spotify.com that you need to set an override for. I was confusing that with the newer non-libspotify endpoint (that also has intermittent problems!)

Looks like I have an issue outside of Mopidy. None of the sites from apresolve.spotify.com are pinging from the pi, but they work from another raspberry pi on my network. I must have bricked some settings when installing something else on the pi (which also serves as a NAS device on my network.) I’ll check back to those instructions and figure out what I did. Thanks for the help! I marked your answer solution as it led me to the root problem.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.