1

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.

1
  • How are you "sending this to the server"? Commented Dec 8, 2010 at 12:15

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

They're probably something to indicate to a primitive HTML generation engine that the characters should not be encoded before sending.
0

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 :-)

1 Comment

This is a comment. Please don't "answer" your own question with a comment. Just update the original.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.