python cgi generates apache exec format error

This is my first attempt at reportlab, a python pdf generator.  I want it to emit the pdf to a browser.  The following program executes okay from the command line, but gives a exec format error in apache.  The execute chmod bit is on.  Please advise.

import cgitb; cgitb.enable()
import cgi
import os
import datetime
import time
import pgdb
import re
import string
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
import sys
from reportlab.lib.units import inch
myCanvas=canvas.Canvas(sys.stdout,pagesize=letter)
width,height=letter
textobject=myCanvas.beginText(0,0)

textobject.setTextOrigin(inch,10*inch)


textobject.textOut("Hello world!")
myCanvas.drawText(textobject)
myCanvas.showPage()
print "Content-type: application/pdf"     # HTML is following
print
myCanvas.save()
astar666Asked:
Who is Participating?
 
efnCommented:
How are you getting to the script through Apache?  Are you trying to use CGI?  What operating system are you using?

I have found with Python CGI scripts under UNIX that I had to put a shebang line at the beginning of the Python script to make it work.  For example:

#!/whereverPythonIs/python

Otherwise, Apache didn't know to run the script with Python.
0
 
efnCommented:
Sorry, I missed the "cgi" in the question title.  The operating system question still applies.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.