[PR #477] [MERGED] Fix issue with hanging authorization process if no port is provided (and updated docs) #911

Closed
opened 2026-02-28 00:02:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/spotipy-dev/spotipy/pull/477
Author: @jonascj
Created: 4/18/2020
Status: Merged
Merged: 4/19/2020
Merged by: @stephanebruckert

Base: masterHead: localhost-port


📝 Commits (3)

  • 4bc2bfc Fixed issue where using rediret uri 'localhost' (without specifying a port) would cause the authorization process to hang (not asking the user to paste/enter the URL redirected to)
  • 37e8e2c Updated the documentation to match the changes to the authorization process - also kind of fixing issues #474 and #471
  • be53659 Fixed Flake8 over-indentation remark

📊 Changes

3 files changed (+63 additions, -31 deletions)

View changed files

📝 docs/index.rst (+47 -24)
📝 spotipy/oauth2.py (+14 -5)
📝 spotipy/util.py (+2 -2)

📄 Description

PR #243 added local http server to accept the auth redirect/callback, eliminating the need to copy and paste a URL during authorization (very cool, I love it).

But from my point of view, and issue #471 and #474 hints at the same thing, PR #243 broke applications / scripts which used redirect uri http://localhost, causing them to hang during authorization (never asking for the URL to be pasted/entered in the console/terminal).

Without this PR the fix is to change redirect uri to http://localhost:8080 (specify a non-privileged port). This PR changes the authorization process logic slightly such that a local host redirect uri with port specified (e.g. http://localhost:8080) will start the local http server, but a local host uri without port specified (e.g. http://localhost) will fallback to the Enter the URL you were redirected to:-method.

With this PR old scripts/applications will continue to run and not hang unexpectedly.

The problem arises because the current Spotipy release starts a local http server (to listen for the redirect/callback) as soon as it detects a redirect uri containing localhost or 127.0.0.1. If no port is specified it defaults to port 8080 but since the request uri argument or envvar is still http://localhost Spotify redirects to http://localhost:80/?code=... and not http://localhost:8080/?code=.... So the local server never receives any requests and hence continues to block execution of the script.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/spotipy-dev/spotipy/pull/477 **Author:** [@jonascj](https://github.com/jonascj) **Created:** 4/18/2020 **Status:** ✅ Merged **Merged:** 4/19/2020 **Merged by:** [@stephanebruckert](https://github.com/stephanebruckert) **Base:** `master` ← **Head:** `localhost-port` --- ### 📝 Commits (3) - [`4bc2bfc`](https://github.com/spotipy-dev/spotipy/commit/4bc2bfcd7a0a57d5b48bd42eae958c3f9bde21e2) Fixed issue where using rediret uri 'localhost' (without specifying a port) would cause the authorization process to hang (not asking the user to paste/enter the URL redirected to) - [`37e8e2c`](https://github.com/spotipy-dev/spotipy/commit/37e8e2cbbb918e6e56c2a179313a9a511f567d85) Updated the documentation to match the changes to the authorization process - also kind of fixing issues #474 and #471 - [`be53659`](https://github.com/spotipy-dev/spotipy/commit/be53659554b46acef852bf9fa455664f5c2470c7) Fixed Flake8 over-indentation remark ### 📊 Changes **3 files changed** (+63 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `docs/index.rst` (+47 -24) 📝 `spotipy/oauth2.py` (+14 -5) 📝 `spotipy/util.py` (+2 -2) </details> ### 📄 Description PR #243 added local http server to accept the auth redirect/callback, eliminating the need to copy and paste a URL during authorization (very cool, I love it). But from my point of view, and issue #471 and #474 hints at the same thing, PR #243 broke applications / scripts which used redirect uri `http://localhost`, causing them to hang during authorization (never asking for the URL to be pasted/entered in the console/terminal). Without this PR the fix is to change redirect uri to `http://localhost:8080` (specify a non-privileged port). This PR changes the authorization process logic slightly such that a local host redirect uri with port specified (e.g. `http://localhost:8080`) will start the local http server, but a local host uri *without* port specified (e.g. `http://localhost`) will fallback to the `Enter the URL you were redirected to:`-method. With this PR old scripts/applications will continue to run and not hang unexpectedly. The problem arises because the current Spotipy release starts a local http server (to listen for the redirect/callback) as soon as it detects a redirect uri containing `localhost` or `127.0.0.1`. If no port is specified it defaults to port `8080` but since the request uri argument or envvar is still `http://localhost` Spotify redirects to `http://localhost:80/?code=...` and not `http://localhost:8080/?code=...`. So the local server never receives any requests and hence continues to block execution of the script. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:02:34 +03:00
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/spotipy#911
No description provided.