简体   繁体   中英

python script will not be executed

I have following script

#!/usr/bin/python

import os
import cgi
import sys



def header():

  header = """
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <html>
    <body bgcolor="#B7B7B7">
    """
  print header

def footer():
  footer = """
    </body>
    </html>
    """


def main():
  try:
    header()
    footer()
  except:
    print "<!-- --><hr><h1>Oops. An error occured.</h1>"
    cgi.print_exception()

main()

This script is called from another script - problem is that is not working. The browser just simply write whole code as plain text beside HTML tags:

#!/usr/bin/python 
import os 
import cgi 
import sys 

def header(): 
    header = """ """ 
    print header 

def footer(): 
    footer = """ """ 

def main(): 
    try: 
        header() 
        footer() 
    except: 
        print "Oops. An error occured." 
        cgi.print_exception() 

main() 

I checked the apache error log, there is nothing about it.

I tried chmod 777, still the same

this is how my config.py looks like:

<Directory "{1}">
AddHandler cgi-script .cgi
Options -Indexes FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all

Python version is 2.7

Do you have any idea how to run this script? Thanks a lot!

What output are you expecting from running this script (which I agree with ergonaut) is not clear how you are doing it.

Running the script independently, it works, but it does not have any natural output...so potentially it is working but you have no means of verifying.

Only other suggestions are calling the python module and breakpointing to see where it fails from an ide (eg eclipse). Also capturing logging error may help, but I presume you have tried both of those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM