473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

CGI module problem: duplicated output

Hello,
I started to learn how to use python with CGI. I went through some
tutorials, but then I found one problem, that seems to be something
stupid. I tried to find answer using google, but I couldn't.

This is my simple CGI script:

#!/usr/bin/python
import cgi

print "Content-type: text/html\n"
print "<html>Hello, world!</html>"

After I run it under Apache I got (HTML source code):

Hello, world!Content-type: text/html Hello, world!

I tried to run it under bash console. I got this:

<html>Hello, world!</html>
Content-type: text/html

<html>Hello, world!</html>

That's very strange for me. I'm using Mandrake 9.2 + Apache 2 + Python
2.3, but the same problem occurs under WinNT + Python 2.1 and WinXP +
Zope + Python 2.3.

Thanks in advance for help!

--
Mimal

Jul 18 '05 #1
6 1234
Mimal <mi****@o2.pl> wrote:

Hello,
I started to learn how to use python with CGI. I went through some
tutorials, but then I found one problem, that seems to be something
stupid. I tried to find answer using google, but I couldn't.

This is my simple CGI script:

#!/usr/bin/python
import cgi

print "Content-type: text/html\n"
print "<html>Hello, world!</html>"


Pardon me for saying so, but I don't believe you. Your script must
actually look like this:

#!/usr/bin/python
import cgi

print "<html>Hello, world!</html>"
print "Content-type: text/html\n"
print "<html>Hello, world!</html>"

That's the only answer that fits your results, and it would produce exactly
the results you describe.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
> Pardon me for saying so, but I don't believe you. Your script must
actually look like this:


Pardon me too, but I know what my script looks like. I'm not such a
fool! I've tested this script under Windows NT + Python 2.1 and Windows
XP + Python 2.3 with the same result.

To prove you, I copied YOUR code and pasted to *.py file. Than I made it
executable and run it using console (./cgi.py). This is what it showed:

<html>Hello, world!</html>
Content-type: text/html

<html>Hello, world!</html>
<html>Hello, world!</html>
Content-type: text/html

<html>Hello, world!</html>

I know it's very strange. I don't get it and that's why I need help. :-)

--
Mimal

Jul 18 '05 #3
Mimal wrote:
Pardon me for saying so, but I don't believe you. Your script must
actually look like this:

Pardon me too, but I know what my script looks like. I'm not such a
fool! I've tested this script under Windows NT + Python 2.1 and Windows
XP + Python 2.3 with the same result.

To prove you, I copied YOUR code and pasted to *.py file. Than I made it
executable and run it using console (./cgi.py). This is what it showed:

<html>Hello, world!</html>
Content-type: text/html

<html>Hello, world!</html>
<html>Hello, world!</html>
Content-type: text/html

<html>Hello, world!</html>

I know it's very strange. I don't get it and that's why I need help. :-)


No it is not strange. What you didn't mention in your first posting is
that you named your file cgi.py. Thus, when you run your script, you
start of by importing it, and therefore the messages are printed twice.

How about renaming it to mimal_cgi.py!

Regards
Jorgen

Jul 18 '05 #4
> How about renaming it to mimal_cgi.py!

For a second I thought: "That's it!" Unfortunately, that doesn't seem to
help. I renamed the file and I got the same. :-(

--
Mimal


Jul 18 '05 #5
> Check there is no cgi.pyc from when the script was still called cgi.py.

Thanks a lot!!! That was it! I should think about the name of the
script. I knew it must be something silly. :-)

--
Mimal

Jul 18 '05 #6
Mimal wrote:
How about renaming it to mimal_cgi.py!

For a second I thought: "That's it!" Unfortunately, that doesn't seem
to help. I renamed the file and I got the same. :-(

Check there is no cgi.pyc from when the script was still called cgi.py.

Cheers, Matt

--
Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenationinternet.com
e: ma**@pollenation.net

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gordon Scott | last post by:
Hi All, I've got a problem I'm seeing when trying to use the struct module to send data to a different machine. Actually I'm making a condensed file that gets transferred to and read on a BREW...
1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
2
by: James S | last post by:
Hi, Basically I've been fighting with this code for a few days now and can't seem to work around this problem. Included is the output, the program I use to get this error and the source code for...
0
by: Terry Hancock | last post by:
Hi all, Suppose you have found a really nice module that does what you want (or will do, it still being in development), and you don't want to waste a lot of duplicated effort, but this module...
11
by: Pieter Provoost | last post by:
I'm having a little filestream problem. With the code below, I open a file in order to insert its contents into another file. However, right after the opening of the file, insertfile.eof() seems to...
2
by: Lumpierbritches | last post by:
I have code that is currently placed in the OnClose Event, and it's duplicated in multiple forms, I would like to convert it to a module and call that module instead of copy and pasting the code....
6
by: Pete | last post by:
Following is a fragment from a program I'm writing. I am trying to enter an 8 bit binary representation from keyboard which is then scanfed into &Ptext and then again into &Key1. This is not binary...
2
by: Mythran | last post by:
I'm trying to add a module template to a project programmatically. I've tried many documented (w/o examples) ways of doing it to no avail. For example, I tried using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.