Cannot access to Odoo External API using PHP 7 XML-RPC - Access Denied, Fatal error Uncaught Ripcord_TransportException

那年仲夏 提交于 2021-02-11 12:06:19

问题


I want to use Odoo's External API on my website, using PHP 7.

Like it is said in the Odoo's documentation, I've placed the Ripcord library in my httpdocs. I have also activated the XML RPC extension on my server, OpenSSL was already activated, and the website is even secured (there's the lock icon in the address bar).

I want to test that with Odoo Demo Trial before we buy licenses. So in my PHP code, I have put the same username/password as the one I used to connect to my Odoo demo account.

1°) But I get faultCode and faultString (Access Denied)

$url = 'https://lgb-test.odoo.com';  // Odoo Demo Trial
$db = 'lgb-test';
$username = 'johndoe@mywebsiteexample.com';  // Same Email as the one to connect to https://lgb-test.odoo.com/web/login
$password = 'mypasswordexample';  // Same Password as the one to connect to https://lgb-test.odoo.com/web/login

require_once('ripcord/ripcord.php');

$common = ripcord::client($url.'/xmlrpc/2/common');
$uid = $common->authenticate($db, $username, $password, array());

echo('UID:');
var_dump($uid);
echo('<br/>');

$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo 'partner=['.$partner.']<br/>';
}
 
echo('VAR_DUMP:<br/>');
var_dump($partners);

Output :

UID:bool(false)
RESULT:
partner=[3]
partner=[Access Denied]
VAR_DUMP:
array(2) { ["faultCode"]=> int(3) ["faultString"]=> string(13) "Access Denied" }

2°) When the start() method is called, I get Fatal error: Uncaught Ripcord_TransportException: Could not access

require_once('ripcord/ripcord.php');        
$info = ripcord::client('https://lgb-test.odoo.com/start/')->start();

echo 'hello';

Output :

Fatal error: Uncaught Ripcord_TransportException: Could not access https://lgb-test.odoo.com/start/ in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php:488 Stack trace: #0 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php(228): Ripcord_Transport_Stream->post('https://lgb-tes...', '<?xml version="...') #1 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/index.php(10): Ripcord_Client->__call('start', Array) #2 {main} thrown in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php on line 488

(Maybe similar posts out there, but somewhat hazy :

How to use PHP7 Ripcord library to get Odoo data? .

Odoo + Ripcord PHP XMLRPC library: "Could not access https://demo.odoo.com/start" )

So, I still don't know what the real problem is.

Any idea please ?


回答1:


1°) After a while searching for a solution, I finally decided to purchase some modules, instead of using the Odoo Demo account.

So, I just changed the credentials for my new database, and also opened the 8069 port for that specific IP Address. And it worked :)

Code :


$url = 'http://xxx.xxx.xxx.xxx:8069';   // Edited here. Opening the 8069 port was the last step to make it work :)
$db = 'thedatabasename';                // Edited here
$username = 'usernameofthataccount';    // Edited here
$password = 'passwordofthataccount';    // Edited here

require_once('ripcord/ripcord.php');

$common = ripcord::client($url.'/xmlrpc/2/common');
$uid = $common->authenticate($db, $username, $password, array());

echo('UID:');
var_dump($uid);
echo('<br/>');

$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo 'partner=['.$partner.']<br/>';
}
 
echo('VAR_DUMP:<br/>');
var_dump($partners);

Output :


UID:int(2)
RESULT:
partner=[568]
partner=[570]
partner=[293]
partner=[378]
partner=[526]
VAR_DUMP:
array(193) { [0]=> int(568) [1]=> int(570) [2]=> int(293) [3]=> int(378) [4]=> int(526)}

2°) The start( ) method won't work with the specific IP Adress though

So, I'm not sure that the start( ) method will work with something else than a Demo account.

Also, Odoo's support told me to not include the "/start" part of the URL in the script. But, with or without the "/start" part, it didn't work.

Code :


require_once('ripcord/ripcord.php');
$info = ripcord::client('http://xxx.xxx.xxx.xxx:8069/start')->start();  // Even using the specific IP, this is ot working in my case

echo 'hello';

Output :


Fatal error: Uncaught Ripcord_TransportException: Could not access http://102.16.10.74:8069/start/ in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php:488 Stack trace: #0 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php(228): Ripcord_Transport_Stream->post('http://102.16.1...', '<?xml version="...') #1 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/index.php(11): Ripcord_Client->__call('start', Array) #2 {main} thrown in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php on line 488

My Conclusion is :

Odoo DEMO has NOT worked for me, even if I followed the instructions from here :

Odoo's documentation



来源:https://stackoverflow.com/questions/65916457/cannot-access-to-odoo-external-api-using-php-7-xml-rpc-access-denied-fatal-er

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!