green43 green43 - 2 months ago 31
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
(Updated:
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):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = 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):
try:
self.sock_common = xmlrpclib.ServerProxy ('http://%s:%s/xmlrpc/common' % (dbhost, xml_port))
self.uid = self.sock_common.login(self.params['dbname'], self.name, self.pswd)

self._read_data()

except:
return

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

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

# Start new User Threads
thread_.start()

# Add threads to thread list
threads.append(thread_)

idx += 1


Please help me..

Answer

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

Comments