Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Pipe Error while uploading playlist cover #633

Open
CaseusNL opened this issue Jan 14, 2021 · 7 comments
Open

Broken Pipe Error while uploading playlist cover #633

CaseusNL opened this issue Jan 14, 2021 · 7 comments

Comments

@CaseusNL
Copy link

CaseusNL commented Jan 14, 2021

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'))
`

@stephanebruckert
Copy link
Member

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!

@gustavokrieger
Copy link
Contributor

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

@stephanebruckert
Copy link
Member

stephanebruckert commented Apr 18, 2021

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

@gustavokrieger
Copy link
Contributor

(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.

@gustavokrieger
Copy link
Contributor

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?

@stephanebruckert
Copy link
Member

stephanebruckert commented 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/ 🐶

@gustavokrieger
Copy link
Contributor

@stephanebruckert Were you able to reproduce the error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants