mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 08:05:55 +03:00
[GH-ISSUE #749] HTTP 401 for playlist_upload_cover_image #454
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#454
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @valentinfrlch on GitHub (Nov 29, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/749
So I have a function that takes an image, converts it into base64 and then makes the PUT request through the built in spotify.playlist_upload_cover_image() function. However I always get a 401. I have already refreshed the token - to no avail. It might also be the scope, but I've tripple-checked
ugc-image-uploadshould be right for uploading a custom playlist cover. What am I doing wrong?Here's the code:
def upload_cover(playlist_id):
scope = "ugc-image-upload"
spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri))
image = open("dataset/thumbnail.jpg", 'rb')
image_read = image.read()
cover_encoded = base64.encodebytes(image_read).strip()
spotify.playlist_upload_cover_image(playlist_id, cover_encoded)
And here's the output:
headers=response.headers,
spotipy.exceptions.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/playlists/playlist_id/images:
Unauthorized., reason: None
@stephanebruckert commented on GitHub (Nov 29, 2021):
Check out the tests to see how it can be done
github.com/plamere/spotipy@48d04f343b/tests/integration/test_user_endpoints.py (L183)I see it's using
base64.b64encode, notbase64.encodebytesgithub.com/plamere/spotipy@48d04f343b/tests/helpers.py (L15)@valentinfrlch commented on GitHub (Nov 29, 2021):
the .decode("utf-8") at the end did the trick!
@valentinfrlch commented on GitHub (Dec 8, 2021):
For some weird reason the suggested solution has only worked once and never since. I have updated my code to the following:
with open("dataset/thumbnail.jpg", 'rb') as image: cover_encoded = base64.b64encode(image.read()).decode("utf-8") spotify.playlist_upload_cover_image(playlist_id, cover_encoded)The only way my code is different from the one in user_endpoint_tests.py is that I read and encode a local file. I don't think the problem is with the way I encode the file, as I have successfully encoded and the decoded the file.
Also I have tried to run the test, and I could get it to pass.
The scope is
"ugc-image-upload"@stephanebruckert commented on GitHub (Dec 8, 2021):
If the issue occurs on the
playlist_upload_cover_imagecall, make sure:It might have worked on a smaller image before.
If this doesn't resolve your issue, please share a complete minimal example with the image you are using, and I will try to help. Thanks!
@valentinfrlch commented on GitHub (Dec 9, 2021):
Thanks for your reply. The image I‘ve tested this with is 80Kb and in JPEG format. I have attatched it below. Here‘s my code:
def upload_cover(playlist_id):
scope = "ugc-image-upload"
spotify = spotipy.Spotify(auth_manager=SpotifyOAuth(
scope=scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri))
# reformat encoding jpg -> base64
with open("dataset/thumbnail.jpg", 'rb') as image:
cover_encoded = base64.b64encode(image.read()).decode("utf-8")
spotify.playlist_upload_cover_image(playlist_id, cover_encoded)
@stephanebruckert commented on GitHub (Dec 10, 2021):
I also get 401, it's strange. It could be linked to https://community.spotify.com/t5/Spotify-for-Developers/Bug-Uploading-cover-image-not-working-with-un-refreshed-access/m-p/5156729#M2056 which would be a bug on the Spotify side, but so far I can't reproduce the suggested solution.
@valentinfrlch commented on GitHub (Dec 13, 2021):
Thank you very much for your reply and also for linking the other thread. Yes it is very strange. Let's hope spotify fixes this soon. Am I right that it does work with a refreshed token? If so, how would I implement this?
@stephanebruckert commented on GitHub (Jan 21, 2022):
@valentinfrlch did you fix it?
@valentinfrlch commented on GitHub (Jan 21, 2022):
No unfortunately not. But I guess all we can really do is to wait for Spotify to fix it, since it's a problem on their end.
@stephanebruckert commented on GitHub (Jan 21, 2022):
I have some live code that is running
playlist_upload_cover_imagesmoothly, uploading covers correctly...github.com/mirrorfm/mirrorfm-core@020e7a2eb3/functions/to-spotify/main.py (L276)It looks identical to the code I tried locally, but what I can do is compare the python/spotipy versions. I'll try to do this ASAP, lacking a bit of time at the moment