Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:46:26+00:00 2026-05-28T07:46:26+00:00

I want to execute a Python CGI Script within a .shtml file, but I

  • 0

I want to execute a Python CGI Script within a .shtml
file, but I just can’t figure out how. I already found several ways?, but nothing seemed to work. And there it was a lot harder to find something that actually shows how to execute a script, and not how to write one ! ;/

My Html:
http://pastebin.com/4sNZTZNQ

And my Script:
http://pastebin.com/w5vGXCBp

I’m very new to CGI and any Webstuff, but I’m programming with Python over half an year now.

PS: Sorry for the confusing formatting of the code, I now uploadednit onto pastebin :S

//edit:
Ok, now some more information, because it still does not work.

From heliohost.org, i was directed to http://area52.heliohost.org/cgi-bin/snakecharmer.py where you can find the paths to python interpreters.

This is my Folder Structure:
– public_html
– .htaccess
– main.py
– index.shtml

Content of .htaccess:

Options +ExecCGI
AddHandler cgi-script .py

Content of main.py:

#! /usr/local/bin/python
print "Content-Type: text/html"
print

print "Hello World!"

Content of index.shtml:
http://pastebin.com/Trg8sXBc

Now, clicking on the link, an “500 InternalServerError” Appears, and I don’t understand why. 🙁

The Server error-log just says this:

[Wed Jun 15 14:41:26 2011] [error] [client 84.151.252.129] File does not exist: /home/nux95/public_html/500.shtml, referer: http: niklasrosenstein.heliohost.org/
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:46:27+00:00Added an answer on May 28, 2026 at 7:46 am

    Here is something I wrote up a while ago.

    There are some tips to getting Python working in CGI.

    1. Always browse the pages through Apache.
      Note that viewing files in the filesystem through a browser works for most things on an html page but will not work for CGI. For scripts to work they must be opened through the htdocs file system. The address line of your browser should look like:

      \\127.0.0.1\index.html or
      \\localhost\index.html
      

      If you open a file up through the file system the CGI will not work. Such as if this is in the location bar of your browser:

      c:\Apache\htdocs\index.html (or some other example location)
      
    2. Convert end of lines of scripts to Unix format:
      Most editors have options to “show end of lines” and then a tool to convert from Unix to PC format. You must have the end of lines set to Unix format.

    3. State the path to the Python interpreter on the first line of the CGI script:
      You must have one of the following lines as the first line of your Python CGI script:

      #!C:\Python25\Python.exe
      #!/usr/bin/python
      

      The top line is used when you are debugging on a PC and the bottom is for a server such as 1and1. I leave the lines as shown and then edit them once they are up on the server by deleting the first line.

    4. Print a content type specifying HTML before printing any other output:
      This can be done simply by adding the following line somewhere very early in your script:

      print "Content-Type: text/html\n\n"
      

      Note that 2 end of lines are required.

    5. Setup Python scripts to give debugging information:
      Import the following to get detailed debugging information.

      import cgitb; cgitb.enable()
      

      An alternative if cgitb is not available is to do the following:

      import sys
      sys.stderr = sys.stdout
      
    6. On the server the python script permissions must be set to execute.
      After uploading your files be sure to edit the first line and set the permissions for the file to execute.

    Check to see if you can hit the python script directly. If you can’t, fix with the above steps (2-6). Then when the Python script is working, debug the shtml.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far to execute a Python program, I'm using > python file.py I want
I want to repeatedly execute a function in Python every 60 seconds forever (just
I want to execute a script every 30mins, but i want to use it
My problem is that I want to execute a python file with an argument
I want to execute assembly code inside a python script. Is that possible? In
I want to execute a non-python program from within python. The non-python program prompts
I want to execute a function every 60 seconds on Python but I don't
I want to execute a Python script on several (15+) remote machine using SSH.
I'm trying to execute a Python script using the Linux crontab . I want
I want to execute python code from C# with following code. static void Main(string[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.