[GH-ISSUE #537] Flask example: OSError: [Errno 48] Address already in use #322

Closed
opened 2026-02-27 23:22:00 +03:00 by kerem · 4 comments
Owner

Originally created by @MikeiLL on GitHub (Jul 11, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/537

In a few Stack Overflow posts, users are suggesting that a scope like: scope='user-read-currently-playing playlist-modify-private' will work, however, at least when I add this to [app.py].(https://github.com/plamere/spotipy/blob/master/examples/app.py), it returns OSError: [Errno 48] Address already in use.

Is this because spotipy.oauth2.SpotifyOAuth is trying to connect two sockets at the same address? Is there a "right" way to do this?

Originally created by @MikeiLL on GitHub (Jul 11, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/537 In a few Stack Overflow posts, users are suggesting that a scope like: `scope='user-read-currently-playing playlist-modify-private'` will work, however, at least when I add this to [app.py].(https://github.com/plamere/spotipy/blob/master/examples/app.py), it returns `OSError: [Errno 48] Address already in use`. Is this because `spotipy.oauth2.SpotifyOAuth` is trying to connect two sockets at the same address? Is there a "right" way to do this?
kerem 2026-02-27 23:22:00 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Jul 12, 2020):

Hey @MikeiLL, I can't reproduce this consistently. I was able to reproduce it once, but that's when I realised I had another app (not python) running on the same port. It might also be a problem specific to Flask

Can you make sure you don't have anything running on port 8080:

kill $(lsof -ti:8080)

and then run the script again and only once. Do you still get the same?

Also how are you usually killing your server? Looks like the best way is to use ctrl + c

<!-- gh-comment-id:657185337 --> @stephanebruckert commented on GitHub (Jul 12, 2020): Hey @MikeiLL, I can't reproduce this consistently. I was able to reproduce it once, but that's when I realised I had another app (not python) running on the same port. It might also be a problem specific to Flask Can you make sure you don't have anything running on port 8080: kill $(lsof -ti:8080) and then run the script again and only once. Do you still get the same? Also how are you usually killing your server? Looks like the best way is to [use ctrl + c](https://stackoverflow.com/a/40042613/1515819)
Author
Owner

@stephanebruckert commented on GitHub (Jul 12, 2020):

I was able to reproduce the OSError: [Errno 48] Address already in use problem consistently by setting a cache path.

spotipy.oauth2.SpotifyOAuth(cache_path='.cache-test')

I guess you are doing the same?

No idea why this is happening, but I'm investigating

Edit: annd I'm unable to reproduce it again. Is it the same for you, happening a bit randomly?

<!-- gh-comment-id:657190967 --> @stephanebruckert commented on GitHub (Jul 12, 2020): I was able to reproduce the `OSError: [Errno 48] Address already in use` problem consistently by setting a cache path. > spotipy.oauth2.SpotifyOAuth(cache_path='.cache-test') I guess you are doing the same? No idea why this is happening, but I'm investigating Edit: annd I'm unable to reproduce it again. Is it the same for you, happening a bit randomly?
Author
Owner

@MikeiLL commented on GitHub (Jul 12, 2020):

For me, so far, it's consistent. Will report back after a bit more testing. Are you able to include an arbitrary number of scopes, even if inconsistently?

Also how are you usually killing your server? Looks like the best way is to use ctrl + c

Yes. On OS X and Unix ctrl + c works. On Windows 10 we have been resorting to the Task Manager app, though someone just told me that alt = f4 may work.

<!-- gh-comment-id:657240582 --> @MikeiLL commented on GitHub (Jul 12, 2020): For me, so far, it's consistent. Will report back after a bit more testing. Are you able to include an arbitrary number of scopes, even if inconsistently? > Also how are you usually killing your server? Looks like the best way is to use ctrl + c Yes. On OS X and Unix ctrl + c works. On Windows 10 we have been resorting to the Task Manager app, though someone just told me that `alt = f4` may work.
Author
Owner

@stephanebruckert commented on GitHub (Jul 12, 2020):

The error seems to appear when the authentication fails (but shouldn't), and then automatically attempts to use this feature: "Spin up a local webserver to auto-fill authentication URL".

Here is a temporary fix for it https://github.com/plamere/spotipy/pull/539/files, although as described in the PR it still needs some work to auto refresh the tokens

<!-- gh-comment-id:657272832 --> @stephanebruckert commented on GitHub (Jul 12, 2020): The error seems to appear when the authentication fails (but shouldn't), and then automatically attempts to use this feature: "Spin up a local webserver to auto-fill authentication URL". Here is a temporary fix for it https://github.com/plamere/spotipy/pull/539/files, although as described in the PR it still needs some work to auto refresh the tokens
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#322
No description provided.