[GH-ISSUE #476] 401 Client Error: Unauthorized for url #281

Closed
opened 2026-02-27 23:21:46 +03:00 by kerem · 1 comment
Owner

Originally created by @CounterPill on GitHub (Apr 18, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/476

Code

spotify = spotipy.Spotify(auth=token)
def imageConvert(img):
    with open(img, "rb") as imageFile:
        str = base64.b64encode(imageFile.read()).decode('utf-8')
    return str
ou = spotify.playlist_upload_cover_image(playlist_id='xxx',image_b64=imageConvert("tmp.jpeg"))

Error

ERROR:spotipy.client:HTTP Error for PUT to https://api.spotify.com/v1/playlists/xxx/images returned 401 due to Unauthorized.
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 170, in _internal_call
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/playlists/xxx/images

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 62, in <module>
ou = spotify.playlist_upload_cover_image(playlist_id='xxx',image_b64=imageConvert("tmp.jpeg"))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 546, in playlist_upload_cover_image
    content_type="image/jpeg",
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 220, in _put
    return self._internal_call("PUT", url, payload, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 185, in _internal_call
    headers=response.headers,
spotipy.exceptions.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/playlists/xxx/images:
 Unauthorized.

why?

Originally created by @CounterPill on GitHub (Apr 18, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/476 **Code** ``` spotify = spotipy.Spotify(auth=token) def imageConvert(img): with open(img, "rb") as imageFile: str = base64.b64encode(imageFile.read()).decode('utf-8') return str ou = spotify.playlist_upload_cover_image(playlist_id='xxx',image_b64=imageConvert("tmp.jpeg")) ``` **Error** ``` ERROR:spotipy.client:HTTP Error for PUT to https://api.spotify.com/v1/playlists/xxx/images returned 401 due to Unauthorized. Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 170, in _internal_call response.raise_for_status() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/playlists/xxx/images During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 62, in <module> ou = spotify.playlist_upload_cover_image(playlist_id='xxx',image_b64=imageConvert("tmp.jpeg")) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 546, in playlist_upload_cover_image content_type="image/jpeg", File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 220, in _put return self._internal_call("PUT", url, payload, kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotipy/client.py", line 185, in _internal_call headers=response.headers, spotipy.exceptions.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/playlists/xxx/images: Unauthorized. ``` why?
kerem 2026-02-27 23:21:46 +03:00
Author
Owner

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

You are most likely missing a scope, see https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/

<!-- gh-comment-id:615873494 --> @stephanebruckert commented on GitHub (Apr 18, 2020): You are most likely missing a scope, see https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/
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#281
No description provided.