[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 896
  • Last Modified:

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()
0
astar666
Asked:
astar666
  • 2
1 Solution
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now