How to use the spotipy.oauth2.SpotifyOauthError 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 bjarneo / Pytify / pytify / pytifylib.py View on Github external
def getCredentials(self):
        try:
            return spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
        except spotipy.oauth2.SpotifyOauthError:
            print('Did not find Spotify credentials.')

            print('Please visit https://github.com/bjarneo/pytify#credentials for more information.')

            sys.exit(1)
github cooperhammond / irs / irs / manager.py View on Github external
def rip_spotify_list(self, type):

        if type == "playlist":
            search = self.args.playlist

        elif type == "album":
            search = self.args.album

        if self.args.artist:
            search += self.args.artist

        try:
            client_credentials_manager = SpotifyClientCredentials(CONFIG["client_id"], CONFIG["client_secret"])
            spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
        except spotipy.oauth2.SpotifyOauthError:
            spotify = spotipy.Spotify()

        if type == "user":
            items = spotify.user_playlists(self.args.user)["items"]
            length = None
        else:
            results = spotify.search(q=search, type=type)
            items = results[type + "s"]['items']
            length = 10

        songs = []

        if len(items) > 0:
            spotify_list = choose_from_spotify_list(items, length=length)

            list_type = spotify_list["type"]
github plamere / spotipy / spotipy / oauth2.py View on Github external
def _request_access_token(self):
        """Gets client credentials access token """
        payload = { 'grant_type': 'client_credentials'}

        headers = _make_authorization_headers(self.client_id, self.client_secret)

        response = requests.post(self.OAUTH_TOKEN_URL, data=payload,
            headers=headers, verify=True, proxies=self.proxies)
        if response.status_code is not 200:
            raise SpotifyOauthError(response.reason)
        token_info = response.json()
        return token_info
github metabrainz / listenbrainz-server / listenbrainz / webserver / views / profile.py View on Github external
def connect_spotify_callback():
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')

    try:
        token = spotify.get_access_token(code)
        spotify.add_new_user(current_user.id, token)
        flash.success('Successfully authenticated with Spotify!')
    except spotipy.oauth2.SpotifyOauthError as e:
        current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True)
        flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0]))

    return redirect(url_for('profile.connect_spotify'))
github plamere / spotipy / spotipy / oauth2.py View on Github external
"""
        You can either provid a client_id and client_secret to the
        constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET
        environment variables
        """
        if not client_id:
            client_id = os.getenv('SPOTIPY_CLIENT_ID')

        if not client_secret:
            client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')

        if not client_id:
            raise SpotifyOauthError('No client id')

        if not client_secret:
            raise SpotifyOauthError('No client secret')

        self.client_id = client_id
        self.client_secret = client_secret
        self.token_info = None
        self.proxies = proxies
github plamere / spotipy / spotipy / oauth2.py View on Github external
def __init__(self, client_id=None, client_secret=None, proxies=None):
        """
        You can either provid a client_id and client_secret to the
        constructor or set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET
        environment variables
        """
        if not client_id:
            client_id = os.getenv('SPOTIPY_CLIENT_ID')

        if not client_secret:
            client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')

        if not client_id:
            raise SpotifyOauthError('No client id')

        if not client_secret:
            raise SpotifyOauthError('No client secret')

        self.client_id = client_id
        self.client_secret = client_secret
        self.token_info = None
        self.proxies = proxies