通过具有适当身份验证的python zeep调用BMC Remedy SOAP WSDL

时间:2019-05-24 12:14:55

标签: php python python-3.x wsdl remedy

我被赋予了为Python中的BMC Remedy调用SOAP WSDL数据的任务。 我只有PHP代码段可供参考。

我有以下问题, 1:我不知道通过Python以及手动(例如通过SOAP UI)在New_GetList_Operation_0方法中传递数据的确切格式,因为我之前只处理过json REST API 2:我只是随机尝试了以下python代码,但出现以下错误: ARERR [149]必须在控制记录中提供用户名

请求就上述两个问题提供帮助。

PHP代码:

public function getRemedyData($params) {
    $client     = new SoapClient($this->_Wsdl, $this->soapOptions);
    $authvalues = new SoapVar($this->_bmcAuth, SOAP_ENC_OBJECT);
    $header     = new SoapHeader("New_GetList_Operation_0", "AuthenticationInfo", $authvalues, false);
    $client->__setSoapHeaders(array($header));
    try {
        $result                = $client->__soapCall("New_GetList_Operation_0", array($params));
        $resultArray           = array('code' => "0", 'message' => "successful");
        $resultArray["result"] = $result;
    } catch (Exception $e) {
        $errMsg = $e->getMessage();

        $resultArray = array('code' => "1", 'message' => $errMsg);
    }
    return $resultArray;
}

$params = array(
    'Qualification' => '\'Modified Date\' >= "' . $dateTimeValue . '" and \'Categorization Tier 2\' = "<<xx Scan>>" and \'Submitter\' = "validusername"'
);
$result = $this->Remedy->getRemedyData($params);

Python代码:

import zeep
from zeep.wsse.username import UsernameToken
from requests import Session
from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
session = Session()
session.auth = HTTPBasicAuth('<<valid_username>>', '<<valid_password>>')
client = Client("url:8080/arsys/WSDL/public/xx/xx:xx:QueryWebService",
                wsse = UsernameToken('<<valid_username>>', '<<valid_password>>'))
header = zeep.xsd.Element(
    'Security',
    zeep.xsd.ComplexType([
        zeep.xsd.Element(
            'UsernameToken',
            zeep.xsd.ComplexType([
                zeep.xsd.Element('Username',zeep.xsd.String()),
                zeep.xsd.Element('Password',zeep.xsd.String()),
            ])
        ),
    ])
)
header_value = header(UsernameToken={'Username': '<<valid_username>>', 'Password': '<<valid_password>>'})
with client.settings(raw_response=True):
    response = client.service.New_GetList_Operation_0(
        _soapheaders=[header_value],
        Qualification='\'Modified Date\' >= "05/14/2017" and \'Categorization Tier 2\' = "<<xx Scan>>" and \'Submitter\' = "<<valid_username>>"'
    )
print(response.content)

0 个答案:

没有答案