Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

XMLRPC: ImportError: No module named xmlrpc.server

By
Drees Far
on 12/7/15, 5:45 AM 1,388 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.

0
Mirco Strizzi
On 12/7/15, 5:52 AM

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()

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??

Drees Far
on 12/7/15, 5:59 AM

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

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/7/15, 6:31 AM

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

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/7/15, 6:39 AM

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 :/

Drees Far
on 12/7/15, 7:02 AM

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

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/7/15, 7:13 AM

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

Drees Far
on 12/7/15, 7:16 AM

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

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/7/15, 7:18 AM

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)

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/7/15, 11:16 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/7/15, 5:45 AM
Seen: 1388 times
Last updated: 12/7/15, 5:52 AM