Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Create openerp database with xmlrpc through php

By
ThackerS (ts)
on 8/20/14, 2:08 AM 2,999 views

Hi.
I want to create another database in openerp using php through xmlrpc.
Firstly, i located the database creation method on openerp: create_db in addons/base_quality_interrogation.py line 167.

And after that, i create my php code :

<?php
// import of xmlrpc library for php
include('xmlrpc.inc');

/* identifiants of the new database  */
$user = 'admin';
$password = 'my_db';
$dbname = 'my_db';
$lang="en_US";

    $server_url = 'http://localhost:8069'; //server url with security verification
    $client = new xmlrpc_client($server_url . "/xmlrpc/db");
    $client->setSSLVerifyPeer(0);

    $msg = new xmlrpcmsg('create_db'); // method create_db allow us to create a new database on openerp
    $msg->addParam(new xmlrpcval($dbname, "string"));
    $msg->addParam(new xmlrpcval($user,'string'));
    $msg->addParam(new xmlrpcval($password,'string'));
    $msg->addParam(new xmlrpcval($lang,'string'));
    $response = $client->send($msg);
    
    echo "<pre>";
    print_r($response);
    echo "</pre>";
?>


The running of the above php code produce the errors below :

xmlrpcresp Object (

[val] => 0

[valtyp] =>

[errno] => -1

[errstr] => Traceback (most recent call last):

File "C:\openerp\Server\server\.\openerp\service\wsgi_server.py", line 82, in xmlrpc_return

File "C:\openerp\Server\server\.\openerp\netsvc.py", line 296, in dispatch_rpc

File "C:\openerp\Server\server\.\openerp\service\web_services.py", line 120, in dispatch

KeyError: 'Method not found: create_db'

[payload] =>

[hdrs] => Array

(

  [content-type] => text/xml

[content-length] => 628

[server] => Werkzeug/0.8.2 Python/2.6.5

[date] => Wed, 20 Aug 2014 07:02:08 GMT

)

[_cookies] => Array ( )

[content_type] => text/xml

[raw_data] => HTTP/1.0 200 OK

Content-Type: text/xml

Content-Length: 628

Server: Werkzeug/0.8.2 Python/2.6.5

Date: Wed, 20 Aug 2014 07:02:08 GMT

faultCode

Method not found: create_db

faultString

Traceback (most recent call last):

File "C:\openerp\Server\server\.\openerp\service\wsgi_server.py", line 82, in xmlrpc_return

File "C:\openerp\Server\server\.\openerp\netsvc.py", line 296, in dispatch_rpc

File "C:\openerp\Server\server\.\openerp\service\web_services.py", line 120, in dispatch

KeyError: 'Method not found: create_db'

)

?>

I nedd a help. Thank you.

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 8/20/14, 2:42 AM

As Ben Bernard said web_service.py File find methods. exp_create_database Method is available.

so in xmlrpc through PHP You can create Database using the create_database Method.

To clarify things. create_database is bocking version. create is non-blocking version. So if you want to wait until its execution finished, you need create_database. But if you don't want to wait, you can use create method. As a note, for some reason, create method is removed in Odoo 8.

Ben Bernard
on 8/20/14, 3:29 AM
0
Sonia
On 5/26/16, 6:00 PM

Can you please help me to create a database in odoo using php through xmlrpc

according to your experience.Please!!

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 8/20/14, 2:17 AM

You can find available method and its definition in

openerp/service/web_services.py

In your case, check db class. Method definition prefixed with exp_.

So your method of interest is "create" and "exp_create".

Dear friends, i try the recommandation, but i still get error. Here is my php code : setSSLVerifyPeer(0); $msg = new xmlrpcmsg('create_database'); // method create_database allow us to create a new database on openerp $msg->addParam(new xmlrpcval($dbname, "string")); $msg->addParam(new xmlrpcval($user,'string')); $msg->addParam(new xmlrpcval($lang,'string')); $msg->addParam(new xmlrpcval($password,'string')); $response = $client->send($msg); echo "

";
	print_r($response);
	echo "
"; ?> Here is my error: xmlrpcresp Object ( [val] => 0 [valtyp] => [errno] => -1 [errstr] => Access denied. [payload] => [hdrs] => Array ( [content-type] => text/xml [content-length] => 286 [server] => Werkzeug/0.8.2 Python/2.6.5 [date] => Wed, 20 Aug 2014 08:29:42 GMT ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.0 200 OK Content-Type: text/xml Content-Length: 286 Server: Werkzeug/0.8.2 Python/2.6.5 Date: Wed, 20 Aug 2014 08:29:42 GMT faultCode AccessDenied faultString Access denied. ) ?>
ThackerS (ts)
on 8/20/14, 3:32 AM

The previous comment is an error. I post my message in the top. Thank you.

ThackerS (ts)
on 8/20/14, 3:37 AM
-1
ThackerS (ts)
On 8/20/14, 3:35 AM

Dear friends, i try the recommandation, but i still get error.

Here is my php code :

<?php
// import of xmlrpc library for php
include('xmlrpc.inc');

/* identifiants of the new database  */
$user = 'admin';
$password = 'my_db';
$dbname = 'my_db';
$lang="en_US";

    $server_url = 'http://localhost:8069'; //server url with security verification
    $client = new xmlrpc_client($server_url . "/xmlrpc/db");
    $client->setSSLVerifyPeer(0);
    
    $msg = new xmlrpcmsg('create_database'); // method create_database allow us to create a new database on openerp
    $msg->addParam(new xmlrpcval($dbname, "string"));
    $msg->addParam(new xmlrpcval($user,'string'));
    $msg->addParam(new xmlrpcval($lang,'string'));
    $msg->addParam(new xmlrpcval($password,'string'));
    $response = $client->send($msg);

    
    echo "<pre>";
    print_r($response);
    echo "</pre>";
?>

Here is my errors code :

xmlrpcresp Object ( [val] => 0 [valtyp] => [errno] => -1 [errstr] => Access denied. [payload] => [hdrs] => Array ( [content-type] => text/xml [content-length] => 286 [server] => Werkzeug/0.8.2 Python/2.6.5 [date] => Wed, 20 Aug 2014 08:29:42 GMT ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.0 200 OK Content-Type: text/xml Content-Length: 286 Server: Werkzeug/0.8.2 Python/2.6.5 Date: Wed, 20 Aug 2014 08:29:42 GMT faultCode AccessDenied faultString Access denied. )

Where i do errors ?

Add database master password as the first param.

Ben Bernard
on 8/20/14, 3:47 AM

@Thacker Scott: For Access Denied Error. Using Pgadmin select Login Roles and select user right click Role privileges tab check all the check box and try to create DB using code.

Prakash
on 8/20/14, 4:02 AM

I succeeded. Thank you dear friends.

ThackerS (ts)
on 8/20/14, 5:01 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)

Stats

Asked: 8/20/14, 2:08 AM
Seen: 2999 times
Last updated: 5/26/16, 11:07 PM