[GH-ISSUE #776] Getting Error - ConnectionError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. after scraping multiple features of a playlist #476

Open
opened 2026-02-27 23:22:50 +03:00 by kerem · 0 comments
Owner

Originally created by @harshgeek4coder on GitHub (Jan 28, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/776

I have written a custom function which helps to extract playlist features and other tracks information. The function very easily runs for a few playlists but after a certain period of time, I get this specific error :

---------------------------------------------------------------------------
timeout                                   Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _error_catcher(self)
    437             try:
--> 438                 yield
    439 

C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in read_chunked(self, amt, decode_content)
    766                     break
--> 767                 chunk = self._handle_chunk(amt)
    768                 decoded = self._decode(

C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _handle_chunk(self, amt)
    719         else:  # amt > self.chunk_left
--> 720             returned_chunk = self._fp._safe_read(self.chunk_left)
    721             self._fp._safe_read(2)  # Toss the CRLF at the end of the chunk.

C:\ProgramData\Anaconda3\lib\http\client.py in _safe_read(self, amt)
    609         while amt > 0:
--> 610             chunk = self.fp.read(min(amt, MAXAMOUNT))
    611             if not chunk:

C:\ProgramData\Anaconda3\lib\socket.py in readinto(self, b)
    588             try:
--> 589                 return self._sock.recv_into(b)
    590             except timeout:

C:\ProgramData\Anaconda3\lib\ssl.py in recv_into(self, buffer, nbytes, flags)
   1051                   self.__class__)
-> 1052             return self.read(nbytes, buffer)
   1053         else:

C:\ProgramData\Anaconda3\lib\ssl.py in read(self, len, buffer)
    910             if buffer is not None:
--> 911                 return self._sslobj.read(len, buffer)
    912             else:

timeout: The read operation timed out

During handling of the above exception, another exception occurred:

ReadTimeoutError                          Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in generate()
    759                 try:
--> 760                     for chunk in self.raw.stream(chunk_size, decode_content=True):
    761                         yield chunk

C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in stream(self, amt, decode_content)
    571         if self.chunked and self.supports_chunked_reads():
--> 572             for line in self.read_chunked(amt, decode_content=decode_content):
    573                 yield line

C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in read_chunked(self, amt, decode_content)
    792             if self._original_response:
--> 793                 self._original_response.close()
    794 

C:\ProgramData\Anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback)
    129             try:
--> 130                 self.gen.throw(type, value, traceback)
    131             except StopIteration as exc:

C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _error_catcher(self)
    442                 # there is yet no clean way to get at it from this context.
--> 443                 raise ReadTimeoutError(self._pool, None, "Read timed out.")
    444 

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

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9464/3707139734.py in <module>
----> 1 pop_today_hits_world = download_playlist_metadata('spotify','37i9dQZF1DXcBWIGoYBM5M')

~\AppData\Local\Temp/ipykernel_9464/351712990.py in download_playlist_metadata(creator, playlist_id)
     55         related_artists_names=[]
     56         related_artists_ids=[]
---> 57         related_artists = sp.artist_related_artists(track["track"]["album"]["artists"][0]["id"])
     58         for i in related_artists['artists']:
     59             related_artists_names.append(i['name'])

C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in artist_related_artists(self, artist_id)
    419         """
    420         trid = self._get_id("artist", artist_id)
--> 421         return self._get("artists/" + trid + "/related-artists")
    422 
    423     def album(self, album_id):

C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in _get(self, url, args, payload, **kwargs)
    295             kwargs.update(args)
    296 
--> 297         return self._internal_call("GET", url, payload, kwargs)
    298 
    299     def _post(self, url, args=None, payload=None, **kwargs):

C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
    240             response = self._session.request(
    241                 method, url, headers=headers, proxies=self.proxies,
--> 242                 timeout=self.requests_timeout, **args
    243             )
    244 

C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    527         }
    528         send_kwargs.update(settings)
--> 529         resp = self.send(prep, **send_kwargs)
    530 
    531         return resp

C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    685 
    686         if not stream:
--> 687             r.content
    688 
    689         return r

C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in content(self)
    836                 self._content = None
    837             else:
--> 838                 self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
    839 
    840         self._content_consumed = True

C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in generate()
    765                     raise ContentDecodingError(e)
    766                 except ReadTimeoutError as e:
--> 767                     raise ConnectionError(e)
    768             else:
    769                 # Standard file-like object.

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

I tried making new apps and it works then, but later again, the same error repeats.
Any idea what can I do to resolve it ?

Originally created by @harshgeek4coder on GitHub (Jan 28, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/776 I have written a custom function which helps to extract playlist features and other tracks information. The function very easily runs for a few playlists but after a certain period of time, I get this specific error : ``` --------------------------------------------------------------------------- timeout Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _error_catcher(self) 437 try: --> 438 yield 439 C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in read_chunked(self, amt, decode_content) 766 break --> 767 chunk = self._handle_chunk(amt) 768 decoded = self._decode( C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _handle_chunk(self, amt) 719 else: # amt > self.chunk_left --> 720 returned_chunk = self._fp._safe_read(self.chunk_left) 721 self._fp._safe_read(2) # Toss the CRLF at the end of the chunk. C:\ProgramData\Anaconda3\lib\http\client.py in _safe_read(self, amt) 609 while amt > 0: --> 610 chunk = self.fp.read(min(amt, MAXAMOUNT)) 611 if not chunk: C:\ProgramData\Anaconda3\lib\socket.py in readinto(self, b) 588 try: --> 589 return self._sock.recv_into(b) 590 except timeout: C:\ProgramData\Anaconda3\lib\ssl.py in recv_into(self, buffer, nbytes, flags) 1051 self.__class__) -> 1052 return self.read(nbytes, buffer) 1053 else: C:\ProgramData\Anaconda3\lib\ssl.py in read(self, len, buffer) 910 if buffer is not None: --> 911 return self._sslobj.read(len, buffer) 912 else: timeout: The read operation timed out During handling of the above exception, another exception occurred: ReadTimeoutError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in generate() 759 try: --> 760 for chunk in self.raw.stream(chunk_size, decode_content=True): 761 yield chunk C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in stream(self, amt, decode_content) 571 if self.chunked and self.supports_chunked_reads(): --> 572 for line in self.read_chunked(amt, decode_content=decode_content): 573 yield line C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in read_chunked(self, amt, decode_content) 792 if self._original_response: --> 793 self._original_response.close() 794 C:\ProgramData\Anaconda3\lib\contextlib.py in __exit__(self, type, value, traceback) 129 try: --> 130 self.gen.throw(type, value, traceback) 131 except StopIteration as exc: C:\ProgramData\Anaconda3\lib\site-packages\urllib3\response.py in _error_catcher(self) 442 # there is yet no clean way to get at it from this context. --> 443 raise ReadTimeoutError(self._pool, None, "Read timed out.") 444 ReadTimeoutError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. During handling of the above exception, another exception occurred: ConnectionError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_9464/3707139734.py in <module> ----> 1 pop_today_hits_world = download_playlist_metadata('spotify','37i9dQZF1DXcBWIGoYBM5M') ~\AppData\Local\Temp/ipykernel_9464/351712990.py in download_playlist_metadata(creator, playlist_id) 55 related_artists_names=[] 56 related_artists_ids=[] ---> 57 related_artists = sp.artist_related_artists(track["track"]["album"]["artists"][0]["id"]) 58 for i in related_artists['artists']: 59 related_artists_names.append(i['name']) C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in artist_related_artists(self, artist_id) 419 """ 420 trid = self._get_id("artist", artist_id) --> 421 return self._get("artists/" + trid + "/related-artists") 422 423 def album(self, album_id): C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in _get(self, url, args, payload, **kwargs) 295 kwargs.update(args) 296 --> 297 return self._internal_call("GET", url, payload, kwargs) 298 299 def _post(self, url, args=None, payload=None, **kwargs): C:\ProgramData\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params) 240 response = self._session.request( 241 method, url, headers=headers, proxies=self.proxies, --> 242 timeout=self.requests_timeout, **args 243 ) 244 C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 527 } 528 send_kwargs.update(settings) --> 529 resp = self.send(prep, **send_kwargs) 530 531 return resp C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs) 685 686 if not stream: --> 687 r.content 688 689 return r C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in content(self) 836 self._content = None 837 else: --> 838 self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' 839 840 self._content_consumed = True C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in generate() 765 raise ContentDecodingError(e) 766 except ReadTimeoutError as e: --> 767 raise ConnectionError(e) 768 else: 769 # Standard file-like object. ConnectionError: HTTPSConnectionPool(host='api.spotify.com', port=443): Read timed out. ``` I tried making new apps and it works then, but later again, the same error repeats. Any idea what can I do to resolve it ?
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#476
No description provided.