Skip to Content
Menu
This question has been flagged
10 Replies
8210 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.

Avatar
Discard
Best Answer

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.

Avatar
Discard

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.

Best Answer

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

according to your experience.Please!!

Avatar
Discard
Best Answer

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".

Avatar
Discard
Author

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. ) ?>
Author

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

Author Best Answer

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 ?

Avatar
Discard

Add database master password as the first param.

@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.

Author

I succeeded. Thank you dear friends.

Related Posts Replies Views Activity
0
Mar 18
3122
2
Mar 15
9149
1
Mar 15
6188
1
Mar 15
7089
1
Jan 23
3956