last day (15 days later) » 

3:35 PM
1
Q: Ajax: Unable to send Json object to bottle webservice

Tauseef HussainI am trying to understand how the Ajax call works. I am sending a Json object to a bottle python webservice as an URL. $.ajax({ type: "POST", data: {"jstring": JSON.stringify(output)}, url: "http://localhost:8080/salesvolume" , contentType: "application/json; ...

 
@IanAuld Well the error is picked on from the firefox console when the Ajax call was made. Basically the Ajx call doesnt go through and I get the error function alert in return. I am not sure what the stack trace is, I am new with this stuff. Is that something I could check?
 
@TauseefHussain The call is going through, you're just receiving a 500 error from the server. Try rewriting your function as def salesvolume(): return {} and see if your success function gets hit.
 
@SwankSwashbucklers If the call is going through I should see the JSON object added to the URL in my console right? I dont see that. Also when I try to read the Json object in the web service I get an AttributeError
 
@TauseefHussain What does the output of the server look like?
 
127.0.0.1 - - [25/Jun/2015:17:09:13 +0200] "POST /salesvolume HTTP/1.1" 200 915 "http://localhost:8080/index.html" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0" The issue is the JSON Object isnt added to the URL and hence I am unable to read it on the web service. If you see there is nothing added to salesvolume in the url.
 
3:35 PM
@TauseefHussain You're making a post request, nothing would be added to the url. Data only gets encoded in the url if you make a get request.
 
Oops facpalm! I didnt know that. Thank you for this. However i am unable to read the Json object in the web service. I will post the code that i am using to read the obect.
@SwankSwashbucklers jsonstring = request.forms.get('jstring') _jsonparams = json.loads(jsonstring) _studios = _jsonparams.Studios So when i use this bit of code within the function i get the attribute error File "app.py", line 122, in salesvolume _studios = _jsonparams.Studios AttributeError: 'dict' object has no attribute 'Studios' But my object has an attribute Studios.
 
@TauseefHussain Try using jsonstring = request.json.get('jstring')
 
Now I get JSONDecodeError: Expecting value: line 1 column 1 (char 0) on that line.
 
3:57 PM
You don't need to decode the json because bottle automatically does it for you. Try _studios = jsonstring.Studios
Actually it'd probably be _studios = jsonstring["Studios"]
 
Still the same problem
I assume it has got to do with the request method
 
4:16 PM
At lunch right now. I'll take a closer look when I get back
 
Thank you so much! I will look at it simultaneously
 
 
1 hour later…
5:41 PM
Alright, I simulated your setup and did some picking around and I think I know what the issue is.
What is the structure of the data you are sending over the post request
?
 

  last day (15 days later) »