1

I'm writing a function in my python class that 'deletes' a song from a webservice.

In my __ init__ method I initialize self.API, self.SONG_URL, self.RESET_URL and self.SITE_URL. The delete function is what's not working properly.

    def delete_song(self,id):
                song = self.get_song(id)
                r = requests.delete(self.SONG_URL + str(id), data=json.dumps(song))  ##maybe not movie?

I tried to model it after my (correctly working) 'set_song_title' function

     def set_song_title(self,id,title):
            song = self.get_song(id)
            song['title'] = 'Something Else'
            song['apikey'] = self.API
            r = requests.put(self.SONG_URL + str(id), data = json.dumps(song)) #put

Thought I'd include that if it could help. Any thoughts? Maybe I shouldn't pass song? Or maybe I shouldn't invoke get? Thank you!

user3295674
  • 893
  • 5
  • 19
  • 42
  • 1
    You need to define what 'not working properly' means. What are you expecting to happen, what is actually happening? – Lukasa Feb 19 '14 at 09:22
  • Agreed that you need to be more explicit about what's happening that you don't expect. You should also note that while `requests` seems to be happy to pass through a data body with a `DELETE` request, behaviour for sending data with a `DELETE` is at best shakily defined, so you need to be sure that your host receiving the call will do what you expect when receiving the call. A quick search (http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request) indicates some hosts can ignore the body, and some may even reject the request as invalid. – Viktor Haag Feb 19 '14 at 13:26

1 Answers1

0

Your question is entirely too vague.

That said, the one thing that strikes me about your two code samples is the fact that delete_song does not include the apikey value. For example, I'm surprised it isn't written like so

def delete_song(self, id):
    song = self.get_song(id)
    song['apikey'] = self.API
    r = requests.delete(self.SONG_URL + str(id), data=json.dumps(song))

Further saying Maybe I shouldn't pass movie? means nothing to those of us answering your question because the only other reference is in the comment in your first sample.

Ian Stapleton Cordasco
  • 26,944
  • 4
  • 67
  • 72