In an external method, I want to perform an HTTP POST to a remote web site, to submit a record to a database. The remote site requires basic HTTP authentication to submit the data, the users database is in synch with my Zope. My external method: def DoHTTPpost (firstname, lastname, email): """ This function performs an HTTP Post and returns the resulting data. No parsing of the data is done. """ import urllib TheURL = 'http://somedomain.com/databasescript' postData = {'Firstname':firstname, 'Lastname':lastname, 'Email':email} codedData = urllib.urlencode(postData) TheCall = urllib.urlopen(TheURL, codedData) return TheCall.read() This works fine if the authentication on the remote site is switched off. How can I supply the current user's name and password in my urlopen call? What's the syntax and how do I get the current users name and password? If this is not possible in an external method, how could it be done? Cheers Marc
http://user:password@host:port/... --On Sonntag, 23. Februar 2003 18:12 +0000 Marc Burgauer <marc@sharedbase.com> wrote:
In an external method, I want to perform an HTTP POST to a remote web site, to submit a record to a database.
The remote site requires basic HTTP authentication to submit the data, the users database is in synch with my Zope.
My external method:
def DoHTTPpost (firstname, lastname, email): """ This function performs an HTTP Post and returns the resulting data. No parsing of the data is done. """ import urllib TheURL = 'http://somedomain.com/databasescript' postData = {'Firstname':firstname, 'Lastname':lastname, 'Email':email} codedData = urllib.urlencode(postData) TheCall = urllib.urlopen(TheURL, codedData) return TheCall.read()
This works fine if the authentication on the remote site is switched off. How can I supply the current user's name and password in my urlopen call?
What's the syntax and how do I get the current users name and password?
If this is not possible in an external method, how could it be done?
Cheers
Marc
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- --------------------------------------------------------------------- - Andreas Jung http://www.andreas-jung.com - - EMail: andreas at andreas-jung.com - - "Life is too short to (re)write parsers" - ---------------------------------------------------------------------
What's the syntax and how do I get the current users name and password?
There's been at least once recent discusion on this list about that topic. A quick search will probably tell you more than you want to know. In short, though, the username can be gotten through the REQUEST object with AUTHENTICATED_USER. The password, however, is generally more difficult since it is (at best) restricted. If the passwords of your folder are not encrypted (check the encrypt_passwords property on your UserFolder, the default is no) you can try a 'user._getPassword()' where 'user' is a User object. That underscore makes it a private method, and Python Scripts won't allow it, but possibly you can get away with it in an External Method. If not, you can make a small change to the Zope source to allow it: in zope/lib/python/AccessControl/User.py in class SimpleUser add a method like def getPassword(self): """Return password in the clear.""" return self.__ # the password is stored in attribute named "underscore underscore" Then you can call it like container.REQUEST.AUTHENTICATED_USER.getPassword() in a Python Script or <dtml-with AUTHENTICATED_USER> <dtml-var getPassword> </dtml-with> in DTML. Others on this list can tell you why this might be a bad idea. A better idea might be to find a UserFolder which will do this for you or allow you to do it yourself. exUserFolder is always something to look at when dealing with user folders. You might also store your passwords parallel to the internal ones in an accessible place, but this is certainly an even worse idea than above. --jcc
participants (3)
-
Andreas Jung -
J Cameron Cooper -
Marc Burgauer