open erp xml rpc

Asked by vinayrks

I am trying to retrieve data from openerp using xml rpc php i am writing a code to retrieve data please verify the code and provide the solution.

<?php
include('xmlrpc.inc');

$usr='admin';
$pwd='aslasl';
$db='SPCRM';

$url='http://localhost:8069/xmlrpc/common';

$sock= new xmlrpc_client($url);
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($db, "string"));
$msg->addParam(new xmlrpcval($usr, "string"));
$msg->addParam(new xmlrpcval($pwd, "string"));

$resp = $sock->send($msg);
$val = $resp->value();
$id = $val->scalarval();
echo $id;

//search model
$url_search='http://localhost:8069/xmlrpc/object';
$sock_search=new xmlrpc_client($url_search);
$args=array('code'=>new xmlrpcval("fl_01", "string"));
$msg_search=new xmlrpcmsg('execute');
$msg_search->addParam(new xmlrpcval($db, "string"));
$msg_search->addParam(new xmlrpcval($id, "string"));
$msg_search->addParam(new xmlrpcval($pwd, "string"));
$msg_search->addParam(new xmlrpcval("res.partner", "string"));
$msg_search->addParam(new xmlrpcval("search", "string"));
$msg_search->addParam(new xmlrpcval($args, "struct"));

$resp_search= $sock_search->send($msg_search);
$val_search=$resp_search->value();

if ($resp_search->faultCode())
    {
       echo 'Error'.$resp_search->faultString();
     }
     else
     {
       echo 'Your Details are submitted and your refrence id is :'.$resp_search->value()->scalarval();
      }

$url_read='http://localhost:8069/xmlrpc/object';
$sock_read=new xmlrpc_client($url_read);
$msg_read=new xmlrpcmsg('execute');
$arrVal=array('user_id', 'name');
$msg_read->addParam(new xmlrpcval($db, "string"));
$msg_read->addParam(new xmlrpcval($id, "string"));
$msg_read->addParam(new xmlrpcval($pwd, "string"));
$msg_read->addParam(new xmlrpcval("res.partner", "string"));
$msg_read->addParam(new xmlrpcval("read", "string"));
$msg_read->addParam(new xmlrpcval(3, "int"));
$msg_read->addParam(new xmlrpcval($arrVal, "struct"));

$resp_read= $sock_read->send($msg_read);

$val_read=$resp_read->value();

$read=$val_read->scalarval();

echo $read;

?>
this code is not working ...it is giving us error

Traceback (most recent call last): File "netsvc.pyo", line 244, in dispatch File "netsvc.pyo", line 73, in __call__ File "C:\Documents and Settings\Bharti\OpenERP AllInOne\Server\addons\base_module_record\base_module_record.py", line 38, in execute File "service\web_services.pyo", line 583, in execute File "osv\osv.pyo", line 59, in wrapper File "osv\osv.pyo", line 118, in execute File "osv\osv.pyo", line 110, in execute_cr File "osv\orm.pyo", line 2827, in search File "osv\orm.pyo", line 2791, in _where_calc TypeError: unhashable type

please provide the solutions

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#1

Hi Vinay,

Looking at the error, I feel its the problem of this line:

$msg_search->addParam(new xmlrpcval($args, "struct"));

The signature of args should be a list,which will contain list/tuple.

examples: args=[] , args=[('name','ilike','Vinay')], args=[['id','=',,3]]

Hope it will help.

Thank you.

Revision history for this message
vinayrks (vinay-rks) said :
#2

Hello Jay,

Thanks for your support, but this isn't the solution to the problem, i have tried this but this answer is not working,

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#3

Hi Vinay,

I am explaining you architectural point of view.
I generated the same error at my end, by passing a dictionary as args.

Here you are calling search method and the signature of search is:
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None):

You may simply try by passing empty array as args and check, it will not crash at your end.

Then you try by passing struct,it will show the error.

Thank you.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#4

Hello Vinay,

instead of $args=array('code'=>new xmlrpcval("fl_01", "string"));

Try this out: $args = array("code", new xmlrpcval(array([0] =>"fl_01",[1] =>"=",[2] =>"string")")))

Thanks.

Revision history for this message
Nitesh Vaghani (nva-openerp) said :
#5

Hi vinay

        Below are two point that need to be focus.

        1) Use only one socket in your whole file. Use only "common" not "object". When you are use this xmlrpc php service check weather you openerp server is start.

        2) For search criteria use below structure

            $args = array(
   new xmlrpcval(array(new xmlrpcval(<table column name> , "string"),
     new xmlrpcval(<operator>,"string"),
     new xmlrpcval(<value you want to search>,"string")),"array"),
  );

           After this change this line $msg_search->addParam(new xmlrpcval($args, "struct")); to $msg_search->addParam(new xmlrpcval($args, "array"));

        Try out this two points,

        Hope this would be help to solve you problem

Revision history for this message
Pinky&TheBrain (coursencore-work) said :
#6

Try:

$arrVal = array(new xmlrpcval('user_id' , "string"), new xmlrpcval('name', "string"));

and

 $msg_read->addParam(new xmlrpcval($arrVal, "array"));

Can you help with this problem?

Provide an answer of your own, or ask vinayrks for more information if necessary.

To post a message you must log in.