Matt
Matt

Reputation: 11

problem executing Javascript from a python cgi

I'm running a Python program on a server and want to provide a client side interface. I'm using a simple web server (from the O'Reilly Programming Python book).

I can generate HTML pages without problems. However now I want to generate a page which includes some JavaScript to validate user input on the client before returning it to the python application on the server. The problematic part of the python code is:

htmlcode = """
`<head`>  ## Heading ##
    `<title`>PAROT - Report Options`</title`>  
    `<script type="text/javascript" src="FormChecks.js"`>
    `</script`>

`</head`>
`<body`>
    `<form method=POST action="cgiRunQuery.py"`>"""'

When I send this to the server, it complains:

tclogin1 - - [08/Dec/2010 10:55:02] "GET /cgi-bin/FormChecks.js HTTP/1.1" 200 -
Traceback (most recent call last):
  File "/usr/lib/python2.6/CGIHTTPServer.py", line 255, in run_cgi
    os.execve(scriptfile, args, os.environ)
OSError: [Errno 8] Exec format error
tclogin1 - - [08/Dec/2010 10:55:02] CGI script exit status 0x7f00

It looks as though the python is trying to execute the JavaScript. If I create a static html page containing the generated html code (including JavaScript), it all works fine.

Upvotes: 1

Views: 2850

Answers (3)

Matt
Matt

Reputation: 1

Firstly. thanks all for taking the time to answer-

I had to but all the back ticks in or else Stack Overflow wouldn't display my HTML code.

If I remove the FormCheck.js from the cgi-bin directory, I get the following from the webserver:

tclogin1 - - [08/Dec/2010 12:42:17] "POST /cgi-bin/cgiGetReportOptions.py HTTP/1.1" 200 - tclogin1 - - [08/Dec/2010 12:42:17] code 404, message No such CGI script ('/cgi-bin/FormChecks.js') tclogin1 - - [08/Dec/2010 12:42:17] "GET /cgi-bin/FormChecks.js HTTP/1.1" 404 -

The server is seeing the

<script type="text/javascript" src="FormChecks.js">

and for some reason trying to run the javascript file as CGI script

Arghhhhhhhhhhhhhhhhhhhh!!!

I've played around some more and the problem was:

<script type="text/javascript" src="/FormChecks.js">

I was missing the "/" before FormChecks.js.

Thanks for all the suggestions - on to solving the next problem now :-)

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799580

Your web server thinks that FormChecks.js is meant to be executed as a CGI script, which of course it's not. Move it outside of cgi-bin/ and change the path in your script tag accordingly. You could also try removing the executable bit from it instead.

Upvotes: 3

Daniel Roseman
Daniel Roseman

Reputation: 600059

What are all those backticks for?

The error seems to be simply that you've got an extra single quote at the end of your closing triple-quote.

Upvotes: 0

Related Questions