Constructing a ZOPE request in a python script
I am hoping that someone can help me with how to construct a POST request in a python script. I tried searching the older messages, but post and get are such common terms, that I didn't have much luck. I have a DTML Document with a form. Right now, it calls a DTML method that stores data in the database. What I am trying to do is insert a python script in between the two to do some data processing. That general procedure works when I use the python script to generate an http GET request. I end up constructing a string something like "foo?bar=true&name=jdoe". Passing that to RESPONSE.redirect() calls the foo DTML method and passes in the variables that I need. However, in my current example, I am trying to pass two variables that contain long strings that contain punctuation marks, whitespace, etc. Using the GET request for these doesn't work. The main problem I am seeing is that whitespace characters seem to be causing part of the redirection string to be ignored. However, I also seem to recall that GET requests were length-limited more so than POST requests (though it's been several years, so my information could be out of date and/or incorrect). In any event, I would like to construct a POST request in the python script instead and then call RESPONSE.redirect(). Can this be done? Thanks for any help. D __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com
--On 3. November 2005 07:34:15 -0800 Dave Coe <zope_user_48103@yahoo.com> wrote:
I am hoping that someone can help me with how to construct a POST request in a python script. I tried searching the older messages, but post and get are such common terms, that I didn't have much luck.
Write an external method and use the httplib to generate a POST request. The Python Library Reference (python.org/doc) has an example. -aj
On 11/3/05, Dave Coe <zope_user_48103@yahoo.com> wrote:
Can this be done?
Yes, but it probably doesn't make much sense. If you did create POST request, Zope would tale that request and convert it into a call to the DTML method. However, your script can just call the DTML method directly instead. No request is necessary. -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/
Dave Coe wrote:
I am hoping that someone can help me with how to construct a POST request in a python script. I tried searching the older messages, but post and get are such common terms, that I didn't have much luck.
This all feels amazingly clunky, but then you are using dtml, so that's to be expected. And you should probably be posting to zope@zope.org, since zope-dev is for development OF, not WITH Zope.
I have a DTML Document with a form. Right now, it calls a DTML method that stores data in the database. What I am trying to do is insert a python script in between the two to do some data processing.
So have the form submit to the python script and have the python script call the ZSQL method: # whatever munging you want x = y + 1 + context.REQUEST.get('something') context.myZSQLMethod(someparam=x) return 'thanks, done!' cheers, Chris PS:
incorrect). In any event, I would like to construct a POST request in the python script instead and then call RESPONSE.redirect(). Can this be done?
No, you can't redirect a POST using a 302 response, especially if you want to process along that way. That's http ;-) -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (4)
-
Andreas Jung -
Chris Withers -
Dave Coe -
Lennart Regebro