7

I can use this verb in the Python Windows SDK. But not in production. Why? What am I doing wrong?

The error message includes (only seen via firebug or fiddler)

Malformed request

or something like that

My code looks like:

from google.appengine.ext import db
from google.appengine.ext import webapp

class Handler(webapp.RequestHandler):
   def delete(self):
       key = self.request.get('key')
       item = db.get(key)
       item.delete()
       self.response.out.write(key)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
  • You say that you are seeing this in production, yes? What do the request logs say in the production admin console? There are a couple of possible exceptional conditions that your code is not handling, and if the code is crashing, you will see some information about it. Also, it would be very helpful to see the actual request that it being sent to AppEngine. – Adam Crossland Mar 08 '10 at 15:07
  • @Adam I have seen nothing in the admin console, just older errors. – Jader Dias Mar 08 '10 at 15:48
  • It would appear, then, that the request isn't even making it all the way to the request handler, so that's not where the problem is. Can you post the actual request itself in the body of your question? – Adam Crossland Mar 08 '10 at 15:50
  • 4
    Are you sending a body in the DELETE request? The HTTP spec says DELETE should not have a body, and the production environment replicates that. – Nick Johnson Mar 08 '10 at 17:02
  • 3
    No, the HTTP spec does not say that, Nick, at least not in Section 9.7. – Julian Reschke Mar 08 '10 at 17:26
  • I gave up from using DELETE so I cannot provide you more details – Jader Dias Mar 08 '10 at 18:02
  • @Nick - Thanks for your response as I've been searching for the solution. I will remove the body for now, but can you double check that spec? I agree with Julian, I don't see anything in there that says that DELETE should not have a body. It actually seems quite ambiguous as it doesn't say it allows it either. It's also worth noting that the spec doesn't specifically limit GET requests either; however, I think it's generally understood that GET doesn't have a request body. I don't know what the right answer is but would love to hear what you think or see a link to an updated spec. Thank you. – jamesmortensen Jan 18 '12 at 21:11
  • You're right, the spec is surprisingly vague. In section 5.1.1 it says "A message-body MUST NOT be included in a request if the specification of the request method (section 5.1.1) does not allow sending an entity-body in requests.", but then _none_ of the method body sections specify a body is prohibited. – Nick Johnson Jan 19 '12 at 00:30
  • I think this comes down on how do you design your REST uris. As the PUT and DELETE are meant to operate on existing elements (see Idempotent Methods), you should provide their id in the uri. So, the need of using the body on the DELETE operation is really not necessary. More help: http://stackoverflow.com/questions/630453/put-vs-post-in-rest http://stackoverflow.com/questions/256349/what-are-the-best-common-restful-url-verbs-and-actions/256359#256359 – Gus Apr 24 '12 at 17:37

1 Answers1

3

Your handler looks OK, are you sure you're sending the request correctly? Using jQuery, this works for me (both using dev_appserver and google app engine production):

$('#delete-button').click(function() {
    $.ajax({
        'type': 'DELETE',
        'url': '/some/url/that/handles/delete'
    })
});

class DeleteHandler(webapp.RequestHandler):

    def delete(self):
        if users.get_current_user() == allowed_user:
            the_data_model.delete()
        else:
            self.response.out.write('Permission denied')

Sending a response body/message did not work for me (e.g. the "permission denied" message in my example won't get to the client). Have you verified your items aren't deleted?

pthulin
  • 4,001
  • 3
  • 21
  • 23