[GH-ISSUE #748] Error with "position" parameter in adding songs to a playlist. #453

Closed
opened 2026-02-27 23:22:42 +03:00 by kerem · 2 comments
Owner

Originally created by @guilevieiram on GitHub (Nov 26, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/748

Hi, i'm having a problem with my application that started occurring a week or so ago.

While trying to add items to a playlist via the api I get the following error message:

HTTP Error for POST to https://api.spotify.com/v1/playlists/2nshq9eTZLRlGH79r2rsRa/tracks with
 Params: {'position': None} returned 400 due to Error parsing JSON.
http status: 400, code:-1 - https://api.spotify.com/v1/playlists/2nshq9eTZLRlGH79r2rsRa/tracks
:
 Error parsing JSON., reason: None

It had worked wonders in the past but right now i am having this error. I'm using vscode, with a python venv in windows. I had it deployed in Heroku as well and it worked very well there as well.

Here is the specific functions causing issues:

def create_playlist(self, song_list: list[str], date: str) -> [str, str]:
        """Creates a playlist given a list of songs. Returns the uri for that playlist."""
        songs_uri: list[str] = [self._get_song_link(song_name=song) for song in song_list]
        playlist_data: dict = self.man.user_playlist_create(user=self.man.me()["id"], name=f"The Best Of   {date}")
        self.man.playlist_add_items(
            playlist_id=playlist_data["id"],
            items=songs_uri
        )
        print(playlist_data)
        return playlist_data["uri"], playlist_data["external_urls"]["spotify"]

And some helper functions / definitions:

    def __init__(self) -> None:
        """Initializes the spotify API authorization with the given client keys."""
        self.man = spotify = spotipy.Spotify(
            auth_manager=SpotifyOAuth(
                scope="playlist-modify-public",
                redirect_uri="https://guile.ga",
                client_id=os.environ["SPOTIPY_CLIENT_ID"],
                client_secret=os.environ["SPOTIPY_CLIENT_SECRET"],
                show_dialog=True,
                cache_path="token.txt"
            ),
        )

    def _get_song_link(self, song_name: str) -> str:
        """Returns a song link(uri) given a song name."""
        response: dict = self.man.search(q=song_name, limit=1, type="track")
        try:
            song_uri: str = response["tracks"]["items"][0]["uri"]
        except IndexError:
            song_uri: str = "spotify:track:4cOdK2wGLETKBW3PvgPWqT" # this returns "never gonna give you up as exception"
        return song_uri

Here is the link to the full project if you are interest or need to get more information.
Thanks a lot for the help!

Originally created by @guilevieiram on GitHub (Nov 26, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/748 Hi, i'm having a problem with my application that started occurring a week or so ago. While trying to add items to a playlist via the api I get the following error message: ``` HTTP Error for POST to https://api.spotify.com/v1/playlists/2nshq9eTZLRlGH79r2rsRa/tracks with Params: {'position': None} returned 400 due to Error parsing JSON. http status: 400, code:-1 - https://api.spotify.com/v1/playlists/2nshq9eTZLRlGH79r2rsRa/tracks : Error parsing JSON., reason: None ``` It had worked wonders in the past but right now i am having this error. I'm using vscode, with a python venv in windows. I had it deployed in Heroku as well and it worked very well there as well. Here is the specific functions causing issues: ``` def create_playlist(self, song_list: list[str], date: str) -> [str, str]: """Creates a playlist given a list of songs. Returns the uri for that playlist.""" songs_uri: list[str] = [self._get_song_link(song_name=song) for song in song_list] playlist_data: dict = self.man.user_playlist_create(user=self.man.me()["id"], name=f"The Best Of {date}") self.man.playlist_add_items( playlist_id=playlist_data["id"], items=songs_uri ) print(playlist_data) return playlist_data["uri"], playlist_data["external_urls"]["spotify"] ``` And some helper functions / definitions: ``` def __init__(self) -> None: """Initializes the spotify API authorization with the given client keys.""" self.man = spotify = spotipy.Spotify( auth_manager=SpotifyOAuth( scope="playlist-modify-public", redirect_uri="https://guile.ga", client_id=os.environ["SPOTIPY_CLIENT_ID"], client_secret=os.environ["SPOTIPY_CLIENT_SECRET"], show_dialog=True, cache_path="token.txt" ), ) def _get_song_link(self, song_name: str) -> str: """Returns a song link(uri) given a song name.""" response: dict = self.man.search(q=song_name, limit=1, type="track") try: song_uri: str = response["tracks"]["items"][0]["uri"] except IndexError: song_uri: str = "spotify:track:4cOdK2wGLETKBW3PvgPWqT" # this returns "never gonna give you up as exception" return song_uri ``` Here is the link to the full project if you are interest or need to get more information. Thanks a lot for the help!
kerem 2026-02-27 23:22:42 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Nov 27, 2021):

I think it would help if you share a minimal, reproducible example. Like just 10 lines that show the problem on a fresh playlist.

<!-- gh-comment-id:980626582 --> @stephanebruckert commented on GitHub (Nov 27, 2021): I think it would help if you share a minimal, reproducible example. Like just 10 lines that show the problem on a fresh playlist.
Author
Owner

@guilevieiram commented on GitHub (Nov 27, 2021):

In writing the example i realised that the bug was in another model of my application. Managed to fix it already
Thank you so much!!

<!-- gh-comment-id:980794362 --> @guilevieiram commented on GitHub (Nov 27, 2021): In writing the example i realised that the bug was in another model of my application. Managed to fix it already Thank you so much!!
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#453
No description provided.