After some searching, I found the following solutions for calling api, which requires the Delete method.
First attempt: (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 attempt: (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 that JSON works in, so I think the problem is with the DELETE method, but I can't get it to work.
In addition, webapp runs on the Google engine, so I canβt install the packages, so I would like to stay in the pre-installed libraries.
Who has a good way to make a delete request in GAE? (I need to send data and headers)
The API defines: developer.spotify.com/web-api/, and I'm trying to remove a track from a playlist.