You are not logged in Log in Join
You are here: Home » Members » Chui Tey » XMLRPC with ZClasses

Log in
Name

Password

 

XMLRPC with ZClasses

Whats new

I will be posting some follow-up discussion about this topic on http://www.zope.org/Members/teyc/howtoXMLRPC2

[Zope] XML-RPC Woes

Kapil V. Thangavelu [email protected]

Thu, 16 Mar 2000 13:37:07 -0500

  Previous message: [Zope] XML-RPC Woes 
  Next message: [Zope] Zcatalog's TextIndex Question 
  Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 

--------------------------------------------------------------------------------

After getting a few private emails with questions about what i was doing i thought i'd share what i'd learned and some code.

First an apology

I read through my original email and realized that i was a bit to vague to really get any help, mainly because i don't understand what i'm passing through xml-rpc to dtml methods that are expecting Zope stuff (client, mapping, kw).

Second, what i'm doing.

I'm creating an email archive in zope. i wrote up some python code that retrieves/parses email from a pop3 server and then inserts via xml-rpc into a zclass so that it can be archived and cataloged. I got the whole thing working last night by passing the parsed info in a dict via xml-rpc to an external method which took care of adding the Zclasses in Zope, basically following the example from this howto http://www.zope.org/Members/teyc/howxmlrpc

Third, How to do XML-RPC with Amos's patched xmlrpclib.py for authentication:

  1. Assuming you already have the original xmlrpc implementation from pythonware.com installed, copy Amos's xmlrpclib.py over it (WARNING this will basically delete the original).
  2. Fix the subclassing error. Find class BasicAuthTransport(xmlrpclib.Transport): and change it to class BasicAuthTransport(Transport):
  3. Fix the import error. after the comments there are some imports add:

    from base64 import encodestring

Fourth, External Method Code:

all code is provided on as is basis for the purpose of an example. use at your own risk.

def import_mail(self, props): id = props['id'] mailobj=self.manage_addProduct['YourProduct'].YourZClass.createInObjectManager(id,self.REQUEST) mailobj.propertysheets.YourPropertySheet.manage_changeProperties(props) return "Zope is Cool"

this is one of those times you just look at zope and sigh. so much power if you know how to use it. i actually got the basis of this code from the Zope CD that they passed out at the python conference(8). this method is part of the archive folder called below.

Fifth, the XML-RPC call

From the python script without error checking:

        self.zope = xmlrpclib.Server(YourZopeServer,
                 xmlrpclib.BasicAuthTransport(userid, passwd)
        Props = {
            'Id':Whrandom.Randint(0,1000000),
            'To':Prop_list[0],
            'From':Prop_list[1],
            'Subject':Prop_list[2],
            'Date':Prop_list[3],
            'Body':Prop_list[4]
            }
        print Self.Zope.Test_project.Archive.import_mail(Props) 

I hope this helps. if anyone has any examples of passing args to dtml methods via xml-rpc i'd love to see them.

Cheers,

Kapil

"Kapil V. Thangavelu" wrote: > > Hi > > i've spent the day trying to make this work so i thought i'd see if > brighter minds could illuminate the darkness of my night. > > I'm trying to setup an email archiving system in Zope. I've got the > email retrieval setup in an separate python script and a couple of > ZClasses setup in Zope to archive/catalog the emails. My problem is > getting the parsed email info(to, from, body, etc) from the external > script into my Zclasses. i've tried xml-rpc but i keep getting server > errors. i connect to the server and try > > zope.project.archive.addEmail(id) > > but i keep getting a 500 Internal server error message. addEmail is just > a wrapper around the constructor which expects only one parameter the id > of the email Zclass object to create( just something to debug before i > pass in all the params). So what gives? i can call the method from the > web with > > http://localhost/project/archive/addEmail?id=xx > > but how do you call a dtml method with args from xml-rpc. fyi i'm using > amos's patched xmlrpclib for authentication (i fixed the import errors) > > i've trying to reimplement this as a xmlrpc call to an external method > but i would really like to know how to do it with xml-rpc and dtml. > > Thanks > > Kapil > > _______________________________________________ > Zope maillist - [email protected] > 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 )

--------------------------------------------------------------------------------