0

I got some problems when calling RESTful webservice.
I'm running a Django 1.5 project on google app engine now.
And I make use of httplib in python to call a RESTful webservice.
All methods(PUT, GET, DELETE, POST) work well on my local Machine (python 2.7.5, Django 1.5).
However, the behavior is changed on GAE...
PUT (used to store the data which user edited his information on the sites.), POST method is work well.
The GET method sometimes can't get the latest results from webservice server (not google datastore, the data are stored in other database server, I use the GET method to fetch the data from that server).
The DELETE method is not working totally on GAE.
Here is my code:

import httplib

args = ""
headers = {"Accept":"application/json"}
conn = httplib.HTTPConnection(IP, 8080)
try:
    conn.request("DELETE", Some_API_Method_Url, args, headers)
    response = conn.getresponse()
    res = response.read()

I can't figure out why this happened, hoping someone can help me :(
Thanks in advance!

UPDATED:
I just found why the DELETE method is not working based on this link.
I send an ajax request which type is delete in my js file to my Django backend with the following code:

$.ajax({
  type:'DELETE',
  url:'some_url',
  data:JSON.stringify({'key':'value'}),
  contentType: 'application/json; charset=utf-8',
  dataType: "text",
  success: function(data){...},
  error: function(data){...}
});

It seems that the appspot doesn't allow the DELETE request with body(data).
so, I changed the type of the AJAX request to POST, and it works...

Community
  • 1
  • 1
Calvin Jeng
  • 47
  • 1
  • 1
  • 7
  • Did you mean the latest results stored in Datastore? If so, it's because of Eventual Consistency https://developers.google.com/appengine/docs/python/datastore/queries#Python_Data_consistency – Mario Sep 03 '14 at 14:35
  • Thanks for your reply :) The results are not stored in the Google Datastore. It is stored in other database server. I fetched the data by its' RESTful API which it provided. – Calvin Jeng Sep 03 '14 at 15:41
  • Then you should doublecheck the connection to that DB. I suspect that might be the problem. It's not storing anything, and obviously it will fail to fetch it or delete it. Could you log (logging.info()) your steps when doing those operations? – Mario Sep 03 '14 at 15:50
  • I'm sure that the data are correctly stored in that DB because I can access that DB directly. However, When I stored the data to that DB and tried to fetch latest data, it still showed the old data. But After some minutes, it can showed the latest data correctly. Nothing I did... Is it possible that gae have some mechanisms like caches...? I also try to disable the cache in the setting of browser. But got same results. I will try to log my steps :) Thanks so much for your recommendations! – Calvin Jeng Sep 03 '14 at 15:59
  • GAE uses memcache but if you're not using Datastore (specifically the ndb module), then you should explicitly save that data into your memcache. What DB are you using? – Mario Sep 03 '14 at 16:02
  • MongoDB, using Java to implement Restful API webservice. It's very strange that All functions work well on my localhost.. but different on GAE – Calvin Jeng Sep 03 '14 at 16:15

0 Answers0