Connecting to odoo using XML-RPC

In this tutorial I will show you how to connect odoo by using XML-RPC. Before going directly into code I have to tell you about XML-RPC.




Connecting to odoo using XML-RPC

What is XML-RPC and why we use it?


XML-RPC is created by Dave winer in 1998. It is XML based protocol, used to transmit information between computer systems through network. RPC stands for remove procedure call and it uses XML to encode the calls. To transmit information it uses HyperText Transfer Protocol (HTTP) request. RPC gives developers a mechanism for defining interfaces that can be called over a network.

By using XML-RPC two or more computers running different operating systems and programs written in different languages to share processing and informations. For example, an Odoo application could talk with a PHP program which in turn talks with Python application that talks with ASP, and so on.

Connecting to odoo using XML-RPC


import xmlrpclib
from openerp.exceptions import except_orm
url = "http://localhost:8009"
db = "your_db_name"
user = "abc@gmail.com"
pwd = "1234"
url = 'http://localhost:8069' or ''
try:
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url), allow_none=1)
uid = common.authenticate(db, user, pwd, {})
if uid == 0:
raise Exception('Credentials are wrong for remote system access')
else:
message = 'Connection Stablished Successfully'
except Exception as e:
raise except_orm(_('Remote system access Issue \n '), _(e))
print('******message*****',message)
return uid, url, db, common, pwd
view raw odoo_xmlrpc.py hosted with ❤ by GitHub