Is There a CGI Expert In the House?? Good Grief!!

Steve Holden sholden at holdenweb.com
Fri May 4 12:19:11 EDT 2001


"Ben Ocean" <zope at thewebsons.com> wrote in message
news:mailman.988991952.4072.python-list at python.org...
> Hi;
> Thanks for trying to help me with this CGI script! Here's what I'm running
> into right now. I'm still trying to capture the data that's being sent to
> the buffer (from a foreign URL as a result of visitors filling out a
> script). I appear to be successful in doing this, but for some reason
can't
> extract the data. Here's my code:
>  >>>
> test = sys.stdin.readline()
> if (test != None):
>    print "test part 1 successful"
> f = open("outfile.txt", "w")
> sys.stdout = f
> sys.stdout.writelines([test])
> sys.stdout = sys.__stout__
> sys.stdin = sys.__stdin__
> f.close()
> <<<
> The test (part 1) is successful, but when I try to send it to outfile.txt
> nothing gets printed to the file. I can't cycle through the data in a for
> loop, either. I have no idea what's in *test*! I'd love to know. How do I
> extract this data?

Ben:

Probably the easiest thing is to suck the whole thing in at once, and write
it out the same way. There's no need to assign your file to sys.stdout to
write it. Here's something that stands a chance of working, but remember:
the sys.stdin you are reading is probably going to be the raw data from the
web form, so it will look a bit weird. Still, I imagine anything at all
would be welcome about now...

test = sys.stdin.read()
f = open("outfile.txt", "w")
f.write(test)
f.close()

That's all!

Line-by-line you could do it this way:

f = open("outfile.txt", "w")
while 1:
    line = sys.stdin.readline()
    if not line:
        break
    f.write(line)
f.close()

Feedback, please...

regards
 Steve





More information about the Python-list mailing list