We help IT Professionals succeed at work.

python cgi generates apache exec format error

astar666
astar666 asked
on
Medium Priority
1,072 Views
Last Modified: 2008-01-09
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()
Comment
Watch Question

Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
efn

Commented:
Sorry, I missed the "cgi" in the question title.  The operating system question still applies.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.