[Zope] stdin.read() in Python script

Janez Jere janez.jere@void.si
Wed, 13 Mar 2002 09:57:56 +0100


sorry but its not working, if i run my echo script (posted in my original
mail, see at the end of this mail).  Python script returns None;
DTML script says that "... REQUEST_METHOD 'POST' ... CONTENT_LENGTH '1200'
..." , but where are 1200 bytes of posted data?



> -----Original Message-----
> From: Andy McKay [mailto:andy@agmweb.ca]
> Sent: Wednesday, March 13, 2002 4:56 AM
> To: Janez Jere; zope@zope.org
> Subject: Re: [Zope] stdin.read() in Python script
>
>
> Oop sorry, just noticed you said Python Script in that case the equivalent
> is:
>
> # 'data' is the key of the posted data we want
> data = context.REQUEST.get('data', None)
> if data is not None:
>     do something
>
> Having a method that just prints out the REQUEST variables is
> always useful
> for debugging anyway ;)
>
> ----- Original Message -----
> From: "Andy McKay" <andy@agmweb.ca>
> To: "Janez Jere" <janez.jere@void.si>; <zope@zope.org>
> Sent: Tuesday, March 12, 2002 7:47 PM
> Subject: Re: [Zope] stdin.read() in Python script
>
>
> > All data posted to Zope is placed in the REQUEST object. Make a DTML
> Method
> > with the content <dtml-var REQUEST> and view the page.
> >
> > ----- Original Message -----
> > From: "Janez Jere" <janez.jere@void.si>
> > To: <zope@zope.org>
> > Sent: Tuesday, March 12, 2002 3:29 PM
> > Subject: [Zope] stdin.read() in Python script
> >
> >
> > > 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()
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Zope maillist  -  Zope@zope.org
> > > http://lists.zope.org/mailman/listinfo/zope
> > > **   No cross posts or HTML encoding!  **
> > > (Related lists -
> > >  http://lists.zope.org/mailman/listinfo/zope-announce
> > >  http://lists.zope.org/mailman/listinfo/zope-dev )
> > >
> >
>