[Zope] stdin.read() in Python script
Janez Jere
janez.jere@void.si
Wed, 13 Mar 2002 00:29:32 +0100
Hi,
I was adviced in comp.lang.python that I have a problem for this mailing
list:
Could you help me port my simple cgi to zope pathon script. Problem
which I am unable to solve is reading posted raw data (legacy client
posts a xml document to my cgi and expects a result). I tried very hard
to find a solution, in mean time i wrote script with mod_python, which
works well, but I need to run it fast in app server.
Among all my attempts the closest solutions are:
request.get(BODY) # BODYFILE a
and
request.stdin.read() # but it is not allowed to access read method.
Thanks, janez
# CGI script and test
import sys, os
if len(sys.argv) == 1:
print 'Content-Type: text/plain'
print
length = os.environ['CONTENT_LENGTH']
#print 'length', length
print repr(sys.stdin.read(int(length))) # !!! how to read posted data !!!
else:
# test echo
url = sys.argv[1]
import urllib2 as w
x= w.urlopen(url, 'abc '*300)
print 'read(%s):\n' % url, x.read()