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 8920573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:18:24+00:00 2026-06-15T06:18:24+00:00

I am a noob; trying to create and use a simple webserver in Python

  • 0

I am a noob; trying to create and use a simple webserver in Python that executes CGI scripts written in Python. I am using Windows XP and Python v3.3.0. I have a “myserver” directory which contains “myserver.py”,”sample.html” and the directory “cgi-bin” which in turn contains “cgi_demo.py”

myserver.py

from http.server import HTTPServer
from http.server import CGIHTTPRequestHandler

port = 8080
host = '127.0.0.1'
server_address = (host,port) 
httpd = HTTPServer(server_address,CGIHTTPRequestHandler)
print("Starting my web server on port "+str(port))
httpd.serve_forever()

cgi_demo.py

import cgi
import cgitb; cgitb.enable()

print("Content-type: text/html")
print
print("<html><body>")
for i in range(0,100):
  print(i,"<br>")
print("</body></html>")

Now the directory listing works fine for “myserver” but not for “cgi-bin”; maybe that is how it is coded – I don’t have a problem here. “sample.html” is retrieved fine too. However, the execution of “cgi_demo.py” is not proper. I get a blank page in the browser; and the console window (which is blank too) appears and disappears. Moreover, on the server’s console I get the message

127.0.0.1 - - [29/Nov/2012 12:00:31] "GET /cgi-bin/cgi_demo.py HTTP/1.1" 200 -
127.0.0.1 - - [29/Nov/2012 12:00:31] command: C:\Python33\python.exe -u "D:\python apps\my web server\cgi-bin\cgi_demo.py" ""
127.0.0.1 - - [29/Nov/2012 12:00:32] CGI script exited OK

Please tell me what is wrong! I get the feeling that the output stream of my script is not connected to the server. What am I doing wrong? Don’t say that I have to extend CGIHTTPRequestHandler!!

  • 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-06-15T06:18:25+00:00Added an answer on June 15, 2026 at 6:18 am

    SORRY for the trouble!

    Well, it is my fault. 2 things to note:

    [1]The console window that appeared and disappeared; it only happens when I use IDLE to execute the server. If the script is already running in a normal windows console then this does not happen. My Feeling was WRONG.

    [2]There is an bug/error in my cgi script. After printing the HTTP header; the print statement that I wrote was just “print” instead of actually being “print()”.This is so embarrassing! But, even then why didn’t the interpreter catch this error?

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

Sidebar

Related Questions

I'm trying to create an Integration Service project that will use a set of
I'm somewhat of a noob to python but I'm trying to create a recursive
I'm trying to create a simple stored procedure which I can use to write
I'm a php noob and trying to create a image resizing script that will
Noob here learning backbone.js. I was trying to create a simple horizontal menu (each
I'm trying to create a list using a loop within a loop. I have
I'm a total noob trying to create a website with PHP. I created a
Just a noob trying to learn, I came out with a problem that when
I'm trying to use the Botan library to create a SHA-256 hash of a
I’m trying to use Python’s Selenium bindings to programmatically interact with websites, as part

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.