Home > OpenERP, Python > Open ERP: The Python Web Services (XMP-RPC Based)

Open ERP: The Python Web Services (XMP-RPC Based)

Open ERP used XMP-RPC communication Protocol using Python language. XML-RPC works by sending a HTTP request to a XML-RPC based server and XML-RPC based client want to call a remote method. Python provide two classes 1st: SimpleXMLRPCServer and 2nd: xmlrpclib. below is an example to understand how its work.

Step 1: Create a folder in your home directory having name ‘PythonXMLRPC’.

Step 2: Create python file having name ‘ServerScript.py’ in ‘PythonXMLRPC’ folder.

Step 3: Paste the below code in ServerScript.py:

# Code starts from here

import SimpleXMLRPCServer
server = SimpleXMLRPCServer.SimpleXMLRPCServer((“localhost”, 8888))
def Sum(val1, val2):
#Note: Remove prefix dots from below two line and insert a single tab or minimum four spaces
….print “PrintMsg Call from Client …… ”
….return val1+val2
server.register_function(Sum,’IntSum’)
#Go into the main listener loop
print “Listening on port 8888”
server.serve_forever()

# Code Ends here

Step 4: Run ServerScript.py in terminal like $ Python ServerScript.py. Now XML-RPC Server is running and listening at 8888 port.

Step 5: Create python file having name ‘ClientScript.py’ in ‘PythonXMLRPC’ folder.

Step 6: Paste the below code in ClientScript.py.

# Code Starts Here

import xmlrpclib
server = xmlrpclib.ServerProxy(“http://localhost:8888”)
print “Please Enter two integers value:”
integer1=raw_input(“Enter Value One: “)
integer1=int(integer1)
integer2=raw_input(“Enter Value One: “)
integer2=int(integer2)
print “Result from Server is : “, server.IntSum(integer1,integer2)

# Code End Here

Step 7: Run ClientScript.py in terminal like $ python ClientScript.py.

Thanks

Categories: OpenERP, Python
  1. January 7, 2011 at 5:33 pm

    Is there one tanning product available in the UK you can suggest?

    • January 7, 2011 at 5:36 pm

      Training of what brother?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: