← Back to team overview

openerp-community team mailing list archive

Launchpad: Solution Req in Webservices

 

I am finding few problems using OPENERP Web services using PHP.
1) The python works fine before, but now giving few errors, the code is
given below,
2) All ports  (8080,8069,80) are covered by OPENERP, therefore cant able
to test php using apache, therefore i uses eclipse with zend PHP
environment for its solution but failed to interface using PHP and web
services that might be the port  problem. I tried different codes in
which one of them is given on second problem.

I will be thankful for solving this problem.

=====================================================
Problem 1:

1) Python File
import xmlrpclib

user = 'admin'
pwd = 'hammad'
dbname = 'op_db'


# Get the uid
sock_common = xmlrpclib.ServerProxy
('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, user, pwd)

#replace localhost with the address of the server
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')

partner = {
   'name': 'sif',
}

partner_id = sock.execute(dbname, uid, pwd, 'res.partner', 'create',
partner)

address = {
   'partner_id': partner_id,
   'type' : 'default',
   'street': 'house no',
   'zip': '1367',
   'city': 'peshawar',
   'phone': '+3281813700',
   'fax': '+3281733501',
}

address_id = sock.execute(dbname, uid, pwd, 'res.partner.address',
'create',
address)

================================================================================
Error
Traceback (most recent call last):
  File "abc.py", line 10, in <module>
    uid = sock_common.login(dbname, user, pwd)
  File "/usr/lib/python2.6/xmlrpclib.py", line 986, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1239, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.6/xmlrpclib.py", line 1027, in request
    headers
xmlrpclib.ProtocolError: <ProtocolError for
localhost:8069/xmlrpc/common: 500 Internal Server Error>
==================================================================================

2) Second Problem: XML-RPC Webservices Using PHP

<?
include 'xmlrpc.inc';
// connect function.
function connect() {
$user="admin";
$password = 'hammad';
$dbname = 'op_db';
$server_url = 'http://localhost:8069/xmlrpc/';

if(isset($_COOKIE["user_id"]) == true) {
if($_COOKIE["user_id"]>0) {
return $_COOKIE["user_id"];
}
}

$sock = new xmlrpc_client($server_url.'common');
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($dbname, "string"));
$msg->addParam(new xmlrpcval($user, "string"));
$msg->addParam(new xmlrpcval($password, "string"));
$resp = $sock->send($msg);
$val = $resp->value();
$id = $val->scalarval();
setcookie("user_id",$id,time()+3600);
if($id > 0) {
print("connect seems to work");
return $id;
}else{
print("oooops, no connect");
return -1;
}
}

/**
* $client = xml-rpc handler
* $relation = name of the relation ex: res.partner
* $attribute = name of the attribute ex:code
* $operator = search term operator ex: ilike, =, !=
* $key=search for
*/

function search($client,$relation,$attribute,$operator,$keys) {
$user = 'admin';
$password = 'hammad';
$userId = -1;
$dbname = 'op_db';
// $server_url = 'http://localhost:8069/xmlrpc/object';

$key = array(new xmlrpcval(array(new xmlrpcval($attribute , "string"),
new xmlrpcval($operator,"string"),
new xmlrpcval($keys,"string")),"array"),
);

if($userId<=0) {
$uid = connect();
}
print ("uid = " . $uid);

$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($dbname, "string"));
$msg->addParam(new xmlrpcval($uid, "int"));
$msg->addParam(new xmlrpcval($password, "string"));
$msg->addParam(new xmlrpcval($relation, "string"));
$msg->addParam(new xmlrpcval("search", "string"));
$msg->addParam(new xmlrpcval($key, "array"));

print_r($msg);

$resp = $client->send($msg);
#
#
if ($resp->faultCode()) {
echo 'Error: '.$resp->faultString();
}
print_r($resp);
$val = $resp->value();
print_r($value);
$ids = $val->scalarval();

return $ids;
}

print("(A)");
//$client = new xmlrpc_client("http://localhost:8069/xmlrpc/object";);

$client = new xmlrpc_client("/xmlrpc/object",'localhost','8069','http');
// main.
print("(B)");
$rpc = connect();
print("(C)");
$res = search($client, 'res.partner', 'ref', 'ilike', 'kunde1');
//$res = search($client, 'res.partner','','','');
print_r($res);
?>
=================================================================
-- 
This message was sent from Launchpad by
Hammad (https://launchpad.net/~hammad2)
using the "Contact this team" link on the OpenERP Community team page
(https://launchpad.net/~openerp-community).
For more information see
https://help.launchpad.net/YourAccount/ContactingPeople



Follow ups