CGI module problem: duplicated output

Discussion in 'Python' started by Mimal, Jan 9, 2004.

  1. Mimal

    Mimal Guest

    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
    Mimal, Jan 9, 2004
    #1
    1. Advertising

  2. Mimal

    Tim Roberts Guest

    Mimal <> 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,
    Providenza & Boekelheide, Inc.
    Tim Roberts, Jan 10, 2004
    #2
    1. Advertising

  3. Mimal

    Mimal Guest

    > 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
    Mimal, Jan 12, 2004
    #3
  4. 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
    =?ISO-8859-1?Q?J=F8rgen_Cederberg?=, Jan 12, 2004
    #4
  5. Mimal

    Mimal Guest

    > 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
    Mimal, Jan 12, 2004
    #5
  6. Mimal

    Matt Goodall Guest

    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:
    Matt Goodall, Jan 12, 2004
    #6
  7. Mimal

    Mimal Guest

    > 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
    Mimal, Jan 12, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kcmU=?=
    Replies:
    0
    Views:
    393
    =?Utf-8?B?QW5kcmU=?=
    Oct 27, 2005
  2. Professor Chen
    Replies:
    0
    Views:
    158
    Professor Chen
    Feb 6, 2006
  3. fatted
    Replies:
    1
    Views:
    127
    Steve Grazzini
    Jul 25, 2003
  4. shumsta
    Replies:
    1
    Views:
    254
    Fabian Pilkowski
    Jul 22, 2005
  5. Replies:
    3
    Views:
    110
Loading...

Share This Page