This question has been flagged
1 Reply
12217 Views

Hello!!!
I am trying to work with XMLRPC.

I have tried this:

from xmlrpc.server import SimpleXMLRPCServer

def is_even(n):

return n%2 == 0

server = SimpleXMLRPCServer(("localhost", 8069))

print("Listening on port 8000...")

So that ihave got this error:

Traceback (most recent call last):

File "add_partner.py", line 1, in <module>

from xmlrpc.server import SimpleXMLRPCServer

ImportError: No module named xmlrpc.server

Please, who can help me.

THanks a lot in advance.

Best Regards.

Avatar
Discard
Best Answer

Hi Dress Far , 


you can try this code:


import xmlrpclib

from SimpleXMLRPCServer import SimpleXMLRPCServer

def is_even(n):

return n%2 == 0

server = SimpleXMLRPCServer(("localhost", 8000))

print "Listening on port 8000..."

server.register_function(is_even, "is_even")

server.serve_forever()

Avatar
Discard
Author

Thanks a lot my friend for your help :) But, my prob is that he doesnt know the imported library should i install some thing or what to use the XMLRPC??

Which python version are you using? The SimpleXMLRPCServer module has been merged into xmlrpc.server in Python 3.

I edited the answer , u can try that code. Please let me know. Thank you

Author

i want to try the function compute_sheet of hr.payroll for example but nothing happenend when i have tried your code with hr.payroll model and 'compute_sheet' function.please help :/

Do you want create a webservice method or you wanna Call an odoo web service method?

Author

i want to calculate a payslip through xmlrpc as if i have clicked on the "Compute Sheet". lets say that the payslip is existing but its not calculated. How can i call the compute_sheet of hr.payslip in xmlrpc

Ok you want to Call an odoo's web service method. It was the first code i sent you. When i m back to office i will post it again

Hi , this is my code to call create lead function of crm.lead object. You can refer to this link https://doc.odoo.com/6.0/developer/6_22_XML-RPC_web_services/. You need to specify your object and name of function you need to call. import xmlrpclib username='youruser' pwd='yourpassword' sock_common = xmlrpclib.ServerProxy ('http://yourip:8069/xmlrpc/common') sock = xmlrpclib.ServerProxy('http://yourip:8069/xmlrpc/object') uid = sock_common.login(dbname, username, pwd) #after login you can call function you need lead = { 'name':'Test', 'phone':'324123457', 'country_id':404 } lead_id = sock.execute(dbname, uid, pwd, 'crm.lead', 'create', lead)