Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

Exception Raised 400 #1563

Open
SheebanWasi opened this issue Apr 29, 2020 · 1 comment
Open

Exception Raised 400 #1563

SheebanWasi opened this issue Apr 29, 2020 · 1 comment

Comments

@SheebanWasi
Copy link

SheebanWasi commented Apr 29, 2020

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

  • I am creating a playlist
  • Adding youtube liked songs to the 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):

  • POST /v1/users/{}/playlists
  • POST /v1/playlists/{}/tracks
  • GET /v1/search?query=track%3A{}+artist%3A{}&type=track&offset=0&limit=20

Expected behaviour:

  • A new song must be added to the Spotify library in a new playlist

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
Copy link

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

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

No branches or pull requests

2 participants