'Bottle.py | request.forms.get() returning NoneType using AJAX
I am trying to send javaScript information into a bottle.py server using AJAX. After trying nearly every solution I could find on stackOverflow, bottle docs, or Google in general. No solutions have worked.
For clarity sake, I have only included the parts of the code pertaining to the AJAX call. Can anyone explain why request.forms.get is returning None, and how to correct that?
This is the JS code:
let rawData = {"user0Name": users[0],
"user0Bucks": userBetaBucks[0],
"user1Name": users[1],
"user1Bucks": userBetaBucks[1],
"user2Name": users[2],
"user2Bucks": userBetaBucks[2],
"user3Name": users[3],
"user3Bucks": userBetaBucks[3],
"user4Name": users[4],
"user4Bucks": userBetaBucks[4]
};
$.ajax({
url: "/updateValues",
type: "POST",
dataType: "json",
data: rawData,
contentType: "application/json;",
});
This is the python code:
@post('/updateValues')
def updateValues():
session = load_session(request)
gameID = session['gameID']
rawInfo = json.load(request.forms.get('data'))
Note: 'session = load_session(request)' is a custom function created for retrieving cookies and loading them for later modification within this function. Such as the gameID you see here.
Solution 1:[1]
Turns out I needed to be using JSON.stringify() on the data. All is fixed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vince D |