[GH-ISSUE #1028] ReadTimeout error when using recommendations functions #614

Closed
opened 2026-02-28 00:00:17 +03:00 by kerem · 2 comments
Owner

Originally created by @ftrichardson on GitHub (Sep 30, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1028

Describe the bug
Over the past week, I've frequently encountered the following timeout error when using the functions sp.recommendations_genre_seeds() or sp.recommendations() in my code:

HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)

I have tried increasing requests_timeout and retries and using different API keys, but more often than not my code still times out when its get to these functions. And no other spotipy functions are yielding this problem when used.

Your code
This is how my code uses those functions:

genres = sp.recommendation_genre_seeds()
tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks']

For the latter, the length of disliked_genres is never greater than 5

Expected behavior
I know I'm using the functions correctly because occasionally I won't receive a timeout error and they'll output what I am looking for. And my program works as expected every time I don't get this timeout error.

Output

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/util.py", line 39, in reraise
    raise value
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 538, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 334, in generate_duo_song_recommendations
    tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks']
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 1658, in recommendations
    return self._get("recommendations", **params)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call
    response = self._session.request(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request
    response = conn.getresponse()
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse
    httplib_response = super().getresponse()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
TimeoutError: The read operation timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment
    raise reraise(type(error), error, _stacktrace)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/util.py", line 39, in reraise
    raise value
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 538, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout
    raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/aux-cord/views.py", line 105, in home
    output_playlist = generate_playlist(user_inputs)
  File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 405, in generate_playlist
    for duo_song_recommendation in generate_duo_song_recommendations(first_track_compilation,
  File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 337, in generate_duo_song_recommendations
    tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks']
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 1658, in recommendations
    return self._get("recommendations", **params)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call
    response = self._session.request(
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 532, in send
    raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)

Environment:
OS: Mac
Python version: 3.10.9
spotipy version: 2.23.0

Originally created by @ftrichardson on GitHub (Sep 30, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1028 **Describe the bug** Over the past week, I've frequently encountered the following timeout error when using the functions `sp.recommendations_genre_seeds()` or `sp.recommendations()` in my code: `HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5)` I have tried increasing requests_timeout and retries and using different API keys, but more often than not my code still times out when its get to these functions. And no other spotipy functions are yielding this problem when used. **Your code** This is how my code uses those functions: `genres = sp.recommendation_genre_seeds()` `tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks']` For the latter, the length of disliked_genres is never greater than 5 **Expected behavior** I know I'm using the functions correctly because occasionally I won't receive a timeout error and they'll output what I am looking for. And my program works as expected every time I don't get this timeout error. **Output** ```python Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request response = conn.getresponse() File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse httplib_response = super().getresponse() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse response.begin() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto return self._sock.recv_into(b) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1274, in recv_into return self.read(nbytes, buffer) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1130, in read return self._sslobj.read(len, buffer) TimeoutError: The read operation timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment raise reraise(type(error), error, _stacktrace) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/util.py", line 39, in reraise raise value File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 538, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 334, in generate_duo_song_recommendations tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks'] File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 1658, in recommendations return self._get("recommendations", **params) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call response = self._session.request( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 532, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 536, in _make_request response = conn.getresponse() File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connection.py", line 461, in getresponse httplib_response = super().getresponse() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse response.begin() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto return self._sock.recv_into(b) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1274, in recv_into return self.read(nbytes, buffer) File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1130, in read return self._sslobj.read(len, buffer) TimeoutError: The read operation timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/retry.py", line 470, in increment raise reraise(type(error), error, _stacktrace) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/util/util.py", line 39, in reraise raise value File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 538, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/aux-cord/views.py", line 105, in home output_playlist = generate_playlist(user_inputs) File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 405, in generate_playlist for duo_song_recommendation in generate_duo_song_recommendations(first_track_compilation, File "/Users/flynnrichardson/Desktop/CS/aux-cord/ui/music_recommender.py", line 337, in generate_duo_song_recommendations tracklist = sp.recommendations(seed_genres = disliked_genres, limit=100)['tracks'] File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 1658, in recommendations return self._get("recommendations", **params) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call response = self._session.request( File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/Users/flynnrichardson/Desktop/CS/djangoenv/lib/python3.10/site-packages/requests/adapters.py", line 532, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. (read timeout=5) ``` **Environment:** OS: Mac Python version: 3.10.9 spotipy version: 2.23.0
kerem 2026-02-28 00:00:17 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kinkyninja commented on GitHub (Oct 1, 2023):

Same bug on my VPS.
No bug on my local computer with different internet provider.

<!-- gh-comment-id:1742057862 --> @kinkyninja commented on GitHub (Oct 1, 2023): Same bug on my VPS. No bug on my local computer with different internet provider.
Author
Owner

@ftrichardson commented on GitHub (Oct 1, 2023):

Thank you! The issue was with my internet provider. I tried on my mobile hotspot and it's working perfectly.

<!-- gh-comment-id:1742115354 --> @ftrichardson commented on GitHub (Oct 1, 2023): Thank you! The issue was with my internet provider. I tried on my mobile hotspot and it's working perfectly.
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#614
No description provided.