After searching for a while, I found the following solutions for an api call that requires the Delete method.
First try: (httplib library)
url = '/v1/users/'+ spotify_user_id +'/playlists/'+ playlist_id +'/tracks' data = json.dumps({"tracks": [{ "uri" : track_uri }]}) headers = { 'Authorization' : 'Bearer ' + access_token, 'Content-Type' : 'application/json' } conn = httplib.HTTPSConnection('api.spotify.com') conn.request('DELETE', url , data, headers) resp = conn.getresponse() content = resp.read() return json.loads(content) This returns:
{u'error': {u'status': 400, u'message': u'Empty JSON body.'}}
Second try:(urllib2 library)
url = 'https://api.spotify.com/v1/users/'+ spotify_user_id +'/playlists/'+ playlist_id +'/tracks' data = json.dumps({"tracks": [{ "uri" : track_uri }]}) headers = { 'Authorization' : 'Bearer ' + access_token, 'Content-Type' : 'application/json' } opener = urllib2.build_opener(urllib2.HTTPHandler) req = urllib2.Request(url, data, headers) req.get_method = lambda: 'DELETE' try: response = opener.open(req).read() return response except urllib2.HTTPError as e: return e This returns:
HTTP 400 Bad Request
I have other functions where the JSON is working, so I guess the problem is with the DELETE method but I can't get it working.
Besides this, the webapp is running on google app engine so i can't install packets so I would like to remain in the pre-installed librarys.
Anyone has a good way to do a Delete request on GAE? (I need to send both data and headers)
The API is spotify: developer.spotify.com/web-api/ and I'm trying to delete a track from a playlist.