From 02cd9b0923a77d9a35484cae881338e3aa001bf5 Mon Sep 17 00:00:00 2001 From: Stephane Bruckert Date: Sat, 11 Apr 2020 17:40:26 +0100 Subject: [PATCH] Improve URL parsing, fixes #171, fixes #253, fixes #276, solves #467 --- CHANGELOG.md | 4 ++++ spotipy/oauth2.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 208ddb0..aaa1469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + + - Fixed miscellaneous issues with parsing of callback URL + ## [2.11.0] - 2020-04-11 ### Added diff --git a/spotipy/oauth2.py b/spotipy/oauth2.py index 5c359f4..c583799 100644 --- a/spotipy/oauth2.py +++ b/spotipy/oauth2.py @@ -314,11 +314,11 @@ class SpotifyOAuth(SpotifyAuthBase): Parameters: - url - the response url """ - - try: - return url.split("?code=")[1].split("&")[0] - except IndexError: - return None + url_split = url.split("?code=") + if len(url_split) <= 1: + return url + else: + return url_split[1].split("&")[0] def _make_authorization_headers(self): return _make_authorization_headers(self.client_id, self.client_secret) @@ -370,7 +370,9 @@ class SpotifyOAuth(SpotifyAuthBase): return self._get_auth_response_interactive() def get_authorization_code(self, response=None): - return self.parse_response_code(response or self.get_auth_response()) + if response: + return self.parse_response_code(response) + return self.get_auth_response() def get_access_token(self, code=None, as_dict=True, check_cache=True): """ Gets the access token for the app given the code