green43 green43 - 1 year ago 130
Python Question

Connection Refused on Concurrent connection to openerp with xmlrpc (via python)

I've tried to build a stress test sistem which provide multiple concurent user login. The scheme is 1 thread for 1 user login. But i cant login with multiple user at the same time (concurent).

At the other side, i've tried to login with multiple user in sequential scheme (with thread.lock and thread.release over login method), and it works.

Can i login with multiple user at the same time on python thread scheme like this?

This is my code
i've update my code, and now i tried to read via xml_rpc with multithread.
Open Connection/Login is OK, but the i always get the Failed Return on Reading Method..

This threading class:

class theUser (threading.Thread):
def __init__(self, threadID, row, dbhost, xml_port, dbuser, dbpassword, dbname):
self.threadID = threadID = str(row[0])
self.pswd = str(row[1])
self.msg = ''
self.xml_port = xml_port
self.params={'dbhost' : dbhost,
'dbuser' : dbuser,
'dbpassword': dbpassword,
'dbname' : dbname,
'user' : str(row[0]),
'password' : str(row[1])

def run(self):
self.sock_common = xmlrpclib.ServerProxy ('http://%s:%s/xmlrpc/common' % (dbhost, xml_port))
self.uid = self.sock_common.login(self.params['dbname'],, self.pswd)



def _read_data(self):
self.ids = [1,2,3,10]
self.sock_common.execute(self.params['dbname'], self.uid, self.params['password'], 'res.partner', 'read', self.ids, ['name'])

This is the main code:

for row in reader:
print idx, xml_port, row

if idx == 0:
header = row

# Create new User threads
thread_ = theUser(idx, row, dbhost, xml_port, dbuser, dbpassword, dbname)

# Start new User Threads

# Add threads to thread list

idx += 1

Please help me..

Answer Source

You forgot xml_port when you create theUser, it should be:

thread_ = theUser(idx, row, dbhost, xml_port, dbuser, dbpassword, dbname)

And self.sock_common won't be set if an exception is raised.You can move it to run() function.

To read res.partner:

def _read_data(self):
    self.ids = [1,2,3,10]
    models = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/object' % (dbhost, xml_port))
    res = models.execute(self.params['dbname'], self.uid, self.params['password'], 'res.partner', 'read', self.ids, ['name'])
    print res

You can check if a given user is permited to read using:

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password,
'res.partner', 'check_access_rights',
['read'], {'raise_exception': False})

If the user can read, it should return true.

This script is from Odoo Web Service API

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download