Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  122] [ 4]  / answers: 1 / hits: 24823  / 11 Years ago, thu, february 20, 2014, 12:00:00

I'm trying to run a python script from a local javascript file (part of a locally running HTML/javascript program).



I've been googling this for hours and found a lot of solutions, none of which actually work for me.



Here is the javascript:



$.ajax({

type: POST,
url: test.py,
data: { param: }
}).done(function( o ) {
alert(OK);
});


The test.py file is in the same folder as the script/html file.



here is the script:



#!/usr/bin/python
import os
filepath = os.getcwd()
def MakeFile(file_name):
temp_path = filepath + file_name
with open(file_name, 'w') as f:
f.write('''
def print_success():
print sucesss
''')
print 'Execution completed.'

MakeFile(bla.txt);


It works fine when run normally.



On my Firefox console I get a not well formed error and the script doesn't create a file. However, I can see that Firefox does fetch the script, as I can view it in my browser by clicking the file name.


More From » python

 Answers
81

In order for the python script to execute it has to be deployed by a web server that supports it via CGI or WSGI, etc.



Check out the docs here: webservers


[#72411] Wednesday, February 19, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminuniquer

Total Points: 63
Total Questions: 121
Total Answers: 96

Location: Cambodia
Member since Thu, May 21, 2020
4 Years ago
;