When I attempt to call cgi.FieldStorage()
in a python3.x
cgi script, I get the following error:
[Traceback: error in module x on line y]:
cgi.FieldStorage()
File "/usr/lib64/python3.3/cgi.py", line 553, in __init__
self.read_single()
File "/usr/lib64/python3.3/cgi.py", line 709, in read_single
self.read_binary()
File "/usr/lib64/python3.3/cgi.py", line 731, in read_binary
self.file.write(data)
TypeError: must be str, not bytes
How do I get my POST data
variable from an ajax call?
Example ajax call:
function (param) {
$.ajax({
type: "POST",
url: "/cgi-bin/mycgi.py/TestMethod",
data: JSON.stringify({"foo": "bar"}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert("Success " + result);
},
error: function () {
alert("Failed");
}
});
}