Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > CGI module problem: duplicated output

Reply
Thread Tools

CGI module problem: duplicated output

 
 
Mimal
Guest
Posts: n/a
 
      01-09-2004
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



 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      01-10-2004
Mimal <(E-Mail Removed)> 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, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
 
Mimal
Guest
Posts: n/a
 
      01-12-2004
> 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



 
Reply With Quote
 
=?ISO-8859-1?Q?J=F8rgen_Cederberg?=
Guest
Posts: n/a
 
      01-12-2004
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

 
Reply With Quote
 
Mimal
Guest
Posts: n/a
 
      01-12-2004
> 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




 
Reply With Quote
 
Matt Goodall
Guest
Posts: n/a
 
      01-12-2004
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: (E-Mail Removed)



 
Reply With Quote
 
Mimal
Guest
Posts: n/a
 
      01-12-2004
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are file scoped variables in a module duplicated with each class instantiation? sln@netherlands.com Perl Misc 3 12-11-2008 10:32 PM
I need some help with browser output in ruby cgi - cgi.rb Professor Chen Ruby 0 02-06-2006 07:08 AM
perl/cgi exploit with bracketed module names passed in as CGI param shumsta Perl Misc 1 07-21-2005 11:30 PM
NTLM and many duplicated requests Tom ASP .Net 6 10-17-2004 11:30 AM
CGI module: getting cgi params from text file redirected to script run on the commandline fatted Perl Misc 1 07-25-2003 01:44 AM



Advertisments