CGI module problem: duplicated output

M

Mimal

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!
 
T

Tim Roberts

Mimal said:
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.
 
M

Mimal

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. :)
 
?

=?ISO-8859-1?Q?J=F8rgen_Cederberg?=

Mimal said:
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
 
M

Mimal

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. :-(
 
M

Matt Goodall

Mimal said:
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
 
M

Mimal

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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top