[GH-ISSUE #633] Broken Pipe Error while uploading playlist cover #378

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

Originally created by @CaseusNL on GitHub (Jan 14, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/633

Whenever I want to upload a new playlist cover I am confronted with a broken pipe error.

`
with open(readConfig("mainImg"), "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())

print(encoded_string)

sp.playlist_upload_cover_image(mainPlaylistID, encoded_string)

`

Which returns:
`
Traceback (most recent call last):
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 913, in _send_output
self.send(message_body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 885, in send
self.sock.sendall(data)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 886, in sendall
v = self.send(data[count:])
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 856, in send
return self._sslobj.write(data)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 581, in write
return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 727, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py", line 410, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 677, in urlopen
chunked=chunked,
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 913, in _send_output
self.send(message_body)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 885, in send
self.sock.sendall(data)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 886, in sendall
v = self.send(data[count:])
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 856, in send
return self._sslobj.write(data)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 581, in write
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "SpotipyTest.py", line 219, in
sp.playlist_upload_cover_image(mainPlaylistID, encoded_string)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 694, in playlist_upload_cover_image
content_type="image/jpeg",
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 306, in _put
return self._internal_call("PUT", url, payload, kwargs)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 242, in _internal_call
timeout=self.requests_timeout, **args
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
`

Originally created by @CaseusNL on GitHub (Jan 14, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/633 Whenever I want to upload a new playlist cover I am confronted with a broken pipe error. ` with open(readConfig("mainImg"), "rb") as image_file: encoded_string = base64.b64encode(image_file.read()) print(encoded_string) sp.playlist_upload_cover_image(mainPlaylistID, encoded_string) ` Which returns: ` Traceback (most recent call last): File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 677, in urlopen chunked=chunked, File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 392, in _make_request conn.request(method, url, **httplib_request_kw) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1083, in request self._send_request(method, url, body, headers) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request self.endheaders(body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders self._send_output(message_body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 913, in _send_output self.send(message_body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 885, in send self.sock.sendall(data) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 886, in sendall v = self.send(data[count:]) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 856, in send return self._sslobj.write(data) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 581, in write return self._sslobj.write(data) BrokenPipeError: [Errno 32] Broken pipe During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send timeout=timeout File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 727, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/util/retry.py", line 410, in increment raise six.reraise(type(error), error, _stacktrace) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/packages/six.py", line 734, in reraise raise value.with_traceback(tb) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 677, in urlopen chunked=chunked, File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 392, in _make_request conn.request(method, url, **httplib_request_kw) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1083, in request self._send_request(method, url, body, headers) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request self.endheaders(body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders self._send_output(message_body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 913, in _send_output self.send(message_body) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/http/client.py", line 885, in send self.sock.sendall(data) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 886, in sendall v = self.send(data[count:]) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 856, in send return self._sslobj.write(data) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/ssl.py", line 581, in write return self._sslobj.write(data) urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "SpotipyTest.py", line 219, in <module> sp.playlist_upload_cover_image(mainPlaylistID, encoded_string) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 694, in playlist_upload_cover_image content_type="image/jpeg", File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 306, in _put return self._internal_call("PUT", url, payload, kwargs) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/spotipy/client.py", line 242, in _internal_call timeout=self.requests_timeout, **args File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 530, in request resp = self.send(prep, **send_kwargs) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/adapters.py", line 498, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe')) `
Author
Owner

@stephanebruckert commented on GitHub (Jan 23, 2021):

I think this is because you are uploading an image that's more than 256KB

Notes
The request should contain a Base64 encoded JPEG image data, maximum payload size is 256 KB.
https://developer.spotify.com/documentation/web-api/reference/#endpoint-upload-custom-playlist-cover

We could definitely catch that exception and display a proper error message. A PR that does that is welcome!

<!-- gh-comment-id:766152067 --> @stephanebruckert commented on GitHub (Jan 23, 2021): I think this is because you are uploading an image that's more than 256KB > Notes > The request should contain a Base64 encoded JPEG image data, maximum payload size is 256 KB. > https://developer.spotify.com/documentation/web-api/reference/#endpoint-upload-custom-playlist-cover We could definitely catch that exception and display a proper error message. A PR that does that is welcome!
Author
Owner

@gustavokrieger commented on GitHub (Apr 18, 2021):

I'll start working on this. Should I fix it on the "v3" branch only?

<!-- gh-comment-id:822027152 --> @gustavokrieger commented on GitHub (Apr 18, 2021): I'll start working on this. Should I fix it on the "v3" branch only?
Author
Owner

@stephanebruckert commented on GitHub (Apr 18, 2021):

Awesome. Nope, that's a fix for v2, so please use the main branch

<!-- gh-comment-id:822034105 --> @stephanebruckert commented on GitHub (Apr 18, 2021): Awesome. Nope, that's a fix for v2, so please use the main branch
Author
Owner

@gustavokrieger commented on GitHub (Apr 21, 2021):

(Running Windows 10, Python 3.7.9)

I couldn't reproduce this exact error. The "closest" I got was:

requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))

That happened when I uploaded the image generated by:

from PIL import Image

image = Image.new('RGB', size=(10_000, 10_000))
image.save("test.jpg")

Which generated a 1.49 MB image.

<!-- gh-comment-id:823685394 --> @gustavokrieger commented on GitHub (Apr 21, 2021): (Running Windows 10, Python 3.7.9) I couldn't reproduce this exact error. The "closest" I got was: `requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionAbortedError(10053, 'An established connection was aborted by the software in your host machine', None, 10053, None))` That happened when I uploaded the image generated by: ``` from PIL import Image image = Image.new('RGB', size=(10_000, 10_000)) image.save("test.jpg") ``` Which generated a 1.49 MB image.
Author
Owner

@gustavokrieger commented on GitHub (Apr 21, 2021):

I ran some other tests.

I uploaded the image generated by:

image = Image.new('RGB', size=(10_000, 1_232))

Which generated a 188 KB image. It uploaded correctly. But when I generated one by running:

image = Image.new('RGB', size=(10_000, 1_233))

Which generated a 191 KB image, it failed with the following error:

spotipy.exceptions.SpotifyException: http status: 413, code:-1 - https://api.spotify.com/v1/playlists/1fYfHp88zjW0kVZItm20gu/images:
 error, reason: None

Which occurred while handling the following:

requests.exceptions.HTTPError: 413 Client Error: Request Entity Too Large for url: https://api.spotify.com/v1/playlists/1fYfHp88zjW0kVZItm20gu/images

So, apparently it failed to upload an image that was smaller than 256 KB. It's because the maximum payload size is 256 KB, not only just the image, right? Am I testing it correctly?

<!-- gh-comment-id:823694743 --> @gustavokrieger commented on GitHub (Apr 21, 2021): I ran some other tests. I uploaded the image generated by: `image = Image.new('RGB', size=(10_000, 1_232))` Which generated a 188 KB image. It uploaded correctly. But when I generated one by running: `image = Image.new('RGB', size=(10_000, 1_233))` Which generated a 191 KB image, it failed with the following error: ``` spotipy.exceptions.SpotifyException: http status: 413, code:-1 - https://api.spotify.com/v1/playlists/1fYfHp88zjW0kVZItm20gu/images: error, reason: None ``` Which occurred while handling the following: `requests.exceptions.HTTPError: 413 Client Error: Request Entity Too Large for url: https://api.spotify.com/v1/playlists/1fYfHp88zjW0kVZItm20gu/images` So, apparently it failed to upload an image that was smaller than 256 KB. It's because the maximum **payload** size is 256 KB, not only just the image, right? Am I testing it correctly?
Author
Owner

@stephanebruckert commented on GitHub (Apr 21, 2021):

I wonder if the size (width x height) matters too? In your case 10000px looks too high.

For example, I think the image must be minimum 300x300px to be uploaded manually. Maybe there is also a maximum limit

To get random images in code, I like to use the dog API https://dog.ceo/dog-api/ 🐶

<!-- gh-comment-id:823831631 --> @stephanebruckert commented on GitHub (Apr 21, 2021): I wonder if the size (width x height) matters too? In your case 10000px looks too high. For example, I think the image must be minimum 300x300px to be uploaded manually. Maybe there is also a maximum limit To get [random images in code](https://github.com/plamere/spotipy/blob/4e1e74bddce6b1680bca974c6571eaef250c0242/tests/integration/test_user_endpoints.py#L169), I like to use the dog API https://dog.ceo/dog-api/ :dog:
Author
Owner

@gustavokrieger commented on GitHub (Apr 21, 2021):

@stephanebruckert Were you able to reproduce the error?

<!-- gh-comment-id:824404551 --> @gustavokrieger commented on GitHub (Apr 21, 2021): @stephanebruckert Were you able to reproduce the error?
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#378
No description provided.