I'm hosting a website off of Bluehost and I'm trying to execute a python script on a button click using AJAX. However every time I click the button the server responds with a 500 error to the python script. More specifically this is the error:
[Sun Nov 30 17:49:26 2014] [error] [client 174.61.70.33] Premature end of script headers: Steap.py, referer: http://steap.co/
This is the AJAX code:
$(document).ready(function(){
$("#steambutton").click(function() {
DisplayLoadingDiv();
$.ajax({
type: "POST",
url: "http://steap.co/cgi-bin/Steap.py",
data: {steamid: "<?php echo $steamprofile['steamid']?>"},
success: function(response) {
$("#steamdiv").html(response);
$("#phisherbutton").show()
},
error: function(response) {
$("#steamdiv").html("An error occured. Please try again.");
}
});
});
});
Basically the div is showing "An error occured. Please try again."
after 0.01 secs of execution, and the console shows that the server responded with a 500 error when trying to load the python script resource.
Steap.py:
Any ideas as to why this is happening?
I'm pretty sure that the issue is, that you're not properly forming an HTTP response in
Steap.py
. Particularly important is theHTTP/1.1 200 OK\n
part (the Status Line)I've set up in my computer a raw TCP socket implementation (using SocketServer) and it correctly renders a page in my web browser by doing the following:
This looks nicely displayed in Chrome:
Needless to say, but this is my
foo(bar)
function:All this said, I'd really, really study how to install a pre-made server (such as Django or Tornado) in your Bluehost "area" (or however you wanna call it). I lean towards Tornado (its usage is very basic, but it'll help a lot so you don't have to "manually" write headers and bodies by yourself)