How to use the spotipy.SpotifyException function in spotipy

To help you get started, we’ve selected a few spotipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plamere / spotipy / tests / authtests.py View on Github external
def test_track_bad_id(self):
        try:
            track = spotify.track(self.bad_id)
            self.assertTrue(False)
        except spotipy.SpotifyException:
            self.assertTrue(True)
github plamere / SmarterPlaylists / server / plugs.py View on Github external
def _get_more_tracks(self):
        _,_,user,_,playlist_id = self.uri.split(':')
        try:
            results = get_spotify().user_playlist_tracks(user, playlist_id,
                limit=self.limit, offset=self.next_offset)
        except spotipy.SpotifyException as e:
            raise engine.PBLException(self, e.msg)

        self.total = results['total']
        for item in results['items']:
            self.track_count += 1
            good_track = True
            ts = parse_date(item['added_at'])
            if self.tracks_added_before >= 0 and ts >= 0 and ts > self.tracks_added_before:
                good_track = False
            if self.tracks_added_since >= 0 and ts >=0 and ts  < self.tracks_added_since:
                good_track = False
            track = item['track']
            # print good_track, ts, self.tracks_added_before, self.tracks_added_since, track['name']
            if good_track and ts >= 0 and track and 'id' in track:
                self.tracks.append( (track['id'], ts) )
                spotify_plugs._add_track(self.name, track)
github WePickOrganization / WePick / spotipyModified / util.py View on Github external
print("Attempting to get authentication code....")
    httpd = MicroServer((SERVERADDRESS.split("://")[1].split(":")[0], PORT), CustomHandler)
    #httpd = MicroServer((SERVERADDRESS), CustomHandler)
    while not httpd.latest_query_components:
        httpd.handle_request()
    httpd.server_close()
    if "error" in httpd.latest_query_components:
        if httpd.latest_query_components["error"][0] == "access_denied":
            raise spotipy.SpotifyException(200, -1, 'The user rejected Spotify access')
        else:
            raise spotipy.SpotifyException(200, -1, 'Unknown error from Spotify authentication server: {}'.format(
                httpd.latest_query_components["error"][0]))
    if "code" in httpd.latest_query_components:
        code = httpd.latest_query_components["code"][0]
    else:
        raise spotipy.SpotifyException(200, -1, 'Unknown response from Spotify authentication server: {}'.format(
            httpd.latest_query_components))
    return code
github WePickOrganization / WePick / spotipyModified / util.py View on Github external
def get_authentication_code():
    print("Attempting to get authentication code....")
    httpd = MicroServer((SERVERADDRESS.split("://")[1].split(":")[0], PORT), CustomHandler)
    #httpd = MicroServer((SERVERADDRESS), CustomHandler)
    while not httpd.latest_query_components:
        httpd.handle_request()
    httpd.server_close()
    if "error" in httpd.latest_query_components:
        if httpd.latest_query_components["error"][0] == "access_denied":
            raise spotipy.SpotifyException(200, -1, 'The user rejected Spotify access')
        else:
            raise spotipy.SpotifyException(200, -1, 'Unknown error from Spotify authentication server: {}'.format(
                httpd.latest_query_components["error"][0]))
    if "code" in httpd.latest_query_components:
        code = httpd.latest_query_components["code"][0]
    else:
        raise spotipy.SpotifyException(200, -1, 'Unknown response from Spotify authentication server: {}'.format(
            httpd.latest_query_components))
    return code
github WePickOrganization / WePick / spotipyModified / util.py View on Github external
def get_authentication_code():
    print("Attempting to get authentication code....")
    httpd = MicroServer((SERVERADDRESS.split("://")[1].split(":")[0], PORT), CustomHandler)
    #httpd = MicroServer((SERVERADDRESS), CustomHandler)
    while not httpd.latest_query_components:
        httpd.handle_request()
    httpd.server_close()
    if "error" in httpd.latest_query_components:
        if httpd.latest_query_components["error"][0] == "access_denied":
            raise spotipy.SpotifyException(200, -1, 'The user rejected Spotify access')
        else:
            raise spotipy.SpotifyException(200, -1, 'Unknown error from Spotify authentication server: {}'.format(
                httpd.latest_query_components["error"][0]))
    if "code" in httpd.latest_query_components:
        code = httpd.latest_query_components["code"][0]
    else:
        raise spotipy.SpotifyException(200, -1, 'Unknown response from Spotify authentication server: {}'.format(
            httpd.latest_query_components))
    return code
github plamere / pbl / pbl / spotify_plugs.py View on Github external
def _annotate_tracks_with_audio_features(tids):
    otids = tlib.annotate_tracks_from_cache('audio', tids)
    if len(otids) > 0:
        stids = set(otids)
        try:
            results = _get_spotify().audio_features(otids)
            for track in results:
                if track and 'id' in track:
                    # print 'audio', json.dumps(track, indent=4)
                    tlib.annotate_track(track['id'], 'audio', track)
        except spotipy.SpotifyException as e:
            # we may get a 404 if we request features for a single
            # track and the track is missing. In this case we can
            # ignore the error
            if e.http_status >= 400 and e.http_status < 500:
                pass
            else:
                raise engine.PBLException(self, e.msg)
github weskerfoot / Spotify-MPD-Sync / spotify_mpd_sync / msplaylist / authenticate.py View on Github external
if not redirect_uri:
        redirect_uri = os.getenv("SPOTIPY_REDIRECT_URI", "http://localhost:8080")

    if not client_id:
        print('''
            You need to set your Spotify API credentials. You can do this by
            setting environment variables like so:

            export SPOTIPY_CLIENT_ID='your-spotify-client-id'
            export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
            export SPOTIPY_REDIRECT_URI='your-app-redirect-url'

            Get your credentials at     
                https://developer.spotify.com/my-applications
        ''')
        raise spotipy.SpotifyException(550, -1, 'no credentials set')

    sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri, 
        scope=scope, cache_path=get_cache_path(username))

    # try to get a valid token for this user, from the cache,
    # if not in the cache, the create a new (this will send
    # the user to a web page where they can authorize this app)

    token_info = sp_oauth.get_cached_token()

    if not token_info:
        redirect_uri_parsed = urlparse(redirect_uri)

        run_server(redirect_uri_parsed.hostname,
                   redirect_uri_parsed.port)
github WePickOrganization / WePick / spotipyModified / util.py View on Github external
if not client_secret:
        client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')

    if not client_id:
        print('''
            You need to set your Spotify API credentials. You can do this by
            setting environment variables like so:

            export SPOTIPY_CLIENT_ID='your-spotify-client-id'
            export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
            export SPOTIPY_REDIRECT_URI='your-app-redirect-url'

            Get your credentials at     
                https://developer.spotify.com/my-applications
        ''')
        raise spotipy.SpotifyException(550, -1, 'no credentials set')

    cache_path = cache_path or ".cache-" + username
    sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, REDIRECT_URI,
        scope=scope, cache_path=cache_path)

    # try to get a valid token for this user, from the cache,
    # if not in the cache, the create a new (this will send
    # the user to a web page where they can authorize this app)

    token_info = sp_oauth.get_cached_token()

    if not token_info:
        print('''

            User authentication requires interaction with your
            web browser. You will be prompted to enter your 
github guirem / plugin-googlecast / resources / spotipy / util.py View on Github external
if not redirect_uri:
        redirect_uri = os.getenv('SPOTIPY_REDIRECT_URI')

    if not client_id:
        print('''
            You need to set your Spotify API credentials. You can do this by
            setting environment variables like so:

            export SPOTIPY_CLIENT_ID='your-spotify-client-id'
            export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
            export SPOTIPY_REDIRECT_URI='your-app-redirect-url'

            Get your credentials at
                https://developer.spotify.com/my-applications
        ''')
        raise spotipy.SpotifyException(550, -1, 'no credentials set')

    cache_path = cache_path or ".cache-" + username
    sp_oauth = oauth2.SpotifyOAuth(client_id, client_secret, redirect_uri,
                                   scope=scope, cache_path=cache_path)

    # try to get a valid token for this user, from the cache,
    # if not in the cache, the create a new (this will send
    # the user to a web page where they can authorize this app)

    token_info = sp_oauth.get_cached_token()

    if not token_info:
        print('''

            User authentication requires interaction with your
            web browser. Once you enter your credentials and
github forslund / spotify-skill / __init__.py View on Github external
def spotify_play(self, dev_id, uris=None, context_uri=None):
        """Start spotify playback and log any exceptions."""
        try:
            self.log.info(u'spotify_play: {}'.format(dev_id))
            self.spotify.play(dev_id, uris, context_uri)
            self.start_monitor()
            self.dev_id = dev_id
        except spotipy.SpotifyException as e:
            # TODO: Catch other conditions?
            if e.http_status == 403:
                self.log.error('Play command returned 403, play is likely '
                               'already in progress. \n {}'.format(repr(e)))
            else:
                raise SpotifyNotAuthorizedError from e
        except Exception as e:
            self.log.exception(e)
            raise