Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
10 Trả lời
8969 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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

according to your experience.Please!!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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. ) ?>
Tác giả

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

Tác giả Câu trả lời hay nhất

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 ?

Ảnh đại diện
Huỷ bỏ

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.

Tác giả

I succeeded. Thank you dear friends.

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 18
4201
2
thg 3 15
10390
1
thg 3 15
7506
1
thg 3 15
8279
1
thg 1 23
5018