[GH-ISSUE #1011] oauth2.py start_local_http_server() non-functional #602

Closed
opened 2026-02-28 00:00:09 +03:00 by kerem · 1 comment
Owner

Originally created by @BryceGattis on GitHub (Aug 14, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1011

Describe the bug
six.moves.BaseHTTPServer's class HTTPServer does not seem to be able to accept a string for the server_address.

Your code
In-context code (requires SPOTIPY_CLIENT_ID|SPOTIPY_CLIENT_SECRET|SPOTIPY_REDIRECT_URI):

from spotipy.oauth2 import SpotifyOAuth

scope = "playlist-modify-public,playlist-modify-private"
auth_manager = SpotifyOAuth(open_browser=True, scope=scope)
local_auth_response = auth_manager._get_auth_response_local_server('8888') # This line fails with TypeError.

Succinct code:

import spotipy.oauth2
spotipy.oauth2.start_local_http_server('8888') # This line fails with TypeError.

Expected behavior
No exception raised.

Output
Python 3.11 traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\venv\Lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server
    server = HTTPServer(("127.0.0.1", port), handler)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\socketserver.py", line 456, in __init__
    self.server_bind()
  File "C:\Program Files\Python311\Lib\http\server.py", line 136, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Program Files\Python311\Lib\socketserver.py", line 472, in server_bind
    self.socket.bind(self.server_address)
TypeError: 'str' object cannot be interpreted as an integer

Python 3.7 traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\37venv\lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server
    server = HTTPServer(("127.0.0.1", port), handler)
  File "C:\Program Files\Python37\lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:\Program Files\Python37\lib\http\server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Program Files\Python37\lib\socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
TypeError: an integer is required (got type str)

Python 2.7 traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\27venv\lib\site-packages\spotipy\oauth2.py", line 457, in _get_auth_response_local_server
    server = start_local_http_server(redirect_port)
  File "...\27venv\lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server
    server = HTTPServer(("127.0.0.1", port), handler)
  File "C:\Program Files\Python27\Lib\SocketServer.py", line 420, in __init__
    self.server_bind()
  File "C:\Program Files\Python27\Lib\BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "C:\Program Files\Python27\Lib\SocketServer.py", line 434, in server_bind
    self.socket.bind(self.server_address)
  File "C:\Program Files\Python27\Lib\socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
TypeError: an integer is required

Environment:

  • OS: Windows 10
  • Python version: 2.7.18, 3.7.9, and 3.11.4
  • spotipy version: 2.22.1
  • your IDE: Pycharm

Additional context
None.

Originally created by @BryceGattis on GitHub (Aug 14, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1011 **Describe the bug** `six.moves.BaseHTTPServer`'s class `HTTPServer` does not seem to be able to accept a string for the `server_address`. **Your code** In-context code (requires SPOTIPY_CLIENT_ID|SPOTIPY_CLIENT_SECRET|SPOTIPY_REDIRECT_URI): ``` from spotipy.oauth2 import SpotifyOAuth scope = "playlist-modify-public,playlist-modify-private" auth_manager = SpotifyOAuth(open_browser=True, scope=scope) local_auth_response = auth_manager._get_auth_response_local_server('8888') # This line fails with TypeError. ``` Succinct code: ``` import spotipy.oauth2 spotipy.oauth2.start_local_http_server('8888') # This line fails with TypeError. ``` **Expected behavior** No exception raised. **Output** Python 3.11 traceback: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "...\venv\Lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server server = HTTPServer(("127.0.0.1", port), handler) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Python311\Lib\socketserver.py", line 456, in __init__ self.server_bind() File "C:\Program Files\Python311\Lib\http\server.py", line 136, in server_bind socketserver.TCPServer.server_bind(self) File "C:\Program Files\Python311\Lib\socketserver.py", line 472, in server_bind self.socket.bind(self.server_address) TypeError: 'str' object cannot be interpreted as an integer ``` Python 3.7 traceback: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "...\37venv\lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server server = HTTPServer(("127.0.0.1", port), handler) File "C:\Program Files\Python37\lib\socketserver.py", line 452, in __init__ self.server_bind() File "C:\Program Files\Python37\lib\http\server.py", line 137, in server_bind socketserver.TCPServer.server_bind(self) File "C:\Program Files\Python37\lib\socketserver.py", line 466, in server_bind self.socket.bind(self.server_address) TypeError: an integer is required (got type str) ``` Python 2.7 traceback: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "...\27venv\lib\site-packages\spotipy\oauth2.py", line 457, in _get_auth_response_local_server server = start_local_http_server(redirect_port) File "...\27venv\lib\site-packages\spotipy\oauth2.py", line 1303, in start_local_http_server server = HTTPServer(("127.0.0.1", port), handler) File "C:\Program Files\Python27\Lib\SocketServer.py", line 420, in __init__ self.server_bind() File "C:\Program Files\Python27\Lib\BaseHTTPServer.py", line 108, in server_bind SocketServer.TCPServer.server_bind(self) File "C:\Program Files\Python27\Lib\SocketServer.py", line 434, in server_bind self.socket.bind(self.server_address) File "C:\Program Files\Python27\Lib\socket.py", line 228, in meth return getattr(self._sock,name)(*args) TypeError: an integer is required ``` **Environment:** - OS: Windows 10 - Python version: 2.7.18, 3.7.9, and 3.11.4 - spotipy version: 2.22.1 - your IDE: Pycharm **Additional context** None.
kerem 2026-02-28 00:00:09 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@BryceGattis commented on GitHub (Aug 14, 2023):

Resolved the issue. The port that you pass to this method must be an integer. 🤕 This was error in the test code I was running above.
Corrected test code would be:

import spotipy.oauth2
spotipy.oauth2.start_local_http_server(8888) # Succeeds!
<!-- gh-comment-id:1676670302 --> @BryceGattis commented on GitHub (Aug 14, 2023): Resolved the issue. The port that you pass to this method must be an integer. 🤕 This was error in the test code I was running above. Corrected test code would be: ``` import spotipy.oauth2 spotipy.oauth2.start_local_http_server(8888) # Succeeds! ```
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#602
No description provided.