spotify / web-api

This issue tracker is no longer used. Join us in the Spotify for Developers forum for support with the Spotify Web API ➡️ https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer
983 stars 79 forks source link

Exception Raised 400 #1563

Open SheebanWasi opened 4 years ago

SheebanWasi commented 4 years ago

Hey, As I am using Spotify API to add youtube liked songs in my private library playlist.

The codes for the following functions are the following:

`def add_song_to_playlist(self):

populate dictionary with our liked songs

    self.get_liked_videos()
    # collect all of uri
    uris = [info["spotify_uri"]
            for song, info in self.all_song_info.items()]

create a new playlist

    playlist_id = self.create_playlist()

add all songs into new playlist

    request_data = json.dumps(uris)
    query = "https://api.spotify.com/v1/playlists/{}/tracks".format(
        playlist_id)
    response = requests.post(
        query,
        data=request_data,
        headers={
            "Content-Type": "application/json",
            "Authorization": "Bearer {}".format(spotify_token)
        }
    )
    # check for valid response status
    response_json = response.json()
    return response_json`

Endpoint(s):

Expected behaviour:

Actual behaviour:

Traceback (most recent call last): File "spotify_youtube.py", line 168, in cp.add_song_to_playlist() File "spotify_youtube.py", line 160, in add_song_to_playlist raise ResponseException(response.status_code) exceptions.ResponseException: Response gave status code 400

codesalatdev commented 4 years ago

Are you filing a bug report? HTTP Status 400 is a bad request, so you probably want to check the data you're sending.