繁体   English   中英

我需要创建一个使用 ZEEP 或 REQUEST 模块调用 SOAP GET 方法的 python 脚本

[英]I need to create a python script which calls SOAP GET method using ZEEP or REQUEST modules

我是python的新手。 我需要从 Oracle 融合云中获取数据。 我想使用 SOAP API 调用在 Oracle 融合云实例上运行 BI 发布者报告并将数据导入 CSV 文件。

我曾尝试使用 python ZEEP 和 REQUESTS 模块,但没有得到预期的结果。

例如:我的 WSDL: https ://xxx.yy.us6.oraclecloud.com/xmlpserver/services/ExternalReportWSSService ?wsdl

我需要使用的操作来自上面的 WSDL 是 'runReport'

当我从 SOAP UI 为“runReport”操作运行此请求时,我得到如下预期结果:

此屏幕截图来自 SOAP UI,我在其中获取了预期的编码数据

我在 python (Python 3.5) 中使用下面的代码来调用这个 API。 我已经使用了 REQUESTS 和 ZEEP:

1.请求模块

from requests.auth import HTTPBasicAuth
from xml.etree import ElementTree


url="https://xxxx.yyyy.us6.oraclecloud.com/xmlpserver/services/ExternalReportWSSService?wsdl"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
   <soap:Header/>
   <soap:Body>
      <pub:runReport>
         <pub:reportRequest>
            <pub:attributeFormat>csv</pub:attributeFormat>
            <!-- Flatten XML should always be false when we have XML type of output to display the XML tags as mentioned in BIP Data Model and display XML structure in as expected format -->
            <pub:flattenXML>false</pub:flattenXML>
            <pub:parameterNameValues>
                  <!--1st Parameter of BIP Report-->    
                  <pub:item>
                  <pub:name>p_name</pub:name>
                  <pub:values>
                      <pub:item>tapan</pub:item>
                  </pub:values>
                  </pub:item>
                  <!--2nd Parameter of BIP Report-->
                  <!--<pub:item>
                  <pub:name>p_to_date</pub:name>
                  <pub:values>
                      <pub:item>10-15-2019</pub:item>
                  </pub:values>
                  </pub:item>-->
            </pub:parameterNameValues>
            <pub:reportAbsolutePath>/Custom/Integration/test_data_rpt.xdo</pub:reportAbsolutePath>
            <!-- Setting sizeOfDataChunkDownload to -1 will return the output to the calling client -->
            <pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
         </pub:reportRequest>
      </pub:runReport>
   </soap:Body>
</soap:Envelope>"""

response = requests.get(url,data=body,headers=headers,auth=HTTPBasicAuth('XXXX', 'XXXX'))
print (response.text)

上面的代码只是给了我 WSDL 中可用的操作列表

2. ZEEP 模块

from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport

wsdl = "https://XXXX.XXXX.us6.oraclecloud.com/xmlpserver/services/ExternalReportWSSService?wsdl"
session = Session()
session.auth = HTTPBasicAuth('XXXX', 'XXXX')

#An additional argument 'transport' is passed with the authentication details
client = Client(wsdl, transport=Transport(session=session))

request_payload= """<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:pub="http://xmlns.oracle.com/oxp/service/PublicReportService">
   <soap:Header/>
   <soap:Body>
      <pub:runReport>
         <pub:reportRequest>
            <pub:attributeFormat>csv</pub:attributeFormat>
            <!-- Flatten XML should always be false when we have XML type of output to display the XML tags as mentioned in BIP Data Model and display XML structure in as expected format -->
            <pub:flattenXML>false</pub:flattenXML>
            <pub:parameterNameValues>
                  <!--1st Parameter of BIP Report-->    
                  <pub:item>
                  <pub:name>p_name</pub:name>
                  <pub:values>
                      <pub:item>tapan</pub:item>
                  </pub:values>
                  </pub:item>
                  <!--2nd Parameter of BIP Report-->
                  <!--<pub:item>
                  <pub:name>p_to_date</pub:name>
                  <pub:values>
                      <pub:item>10-15-2019</pub:item>
                  </pub:values>
                  </pub:item>-->
            </pub:parameterNameValues>
            <pub:reportAbsolutePath>/Custom/Integration/test_data_rpt.xdo</pub:reportAbsolutePath>
            <!-- Setting sizeOfDataChunkDownload to -1 will return the output to the calling client -->
            <pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
         </pub:reportRequest>
      </pub:runReport>
   </soap:Body>
</soap:Envelope>"""

response = client.service.runReport(request_payload)
#Here 'request_data' is the request parameter dictionary.
#Assuming that the operation named 'runReport' is defined in the passed wsdl.

上面的代码不起作用,因为我不确定如何使用 ZEEP 模块传递请求有效负载。

请帮我!!

我已经使用请求模块将报告从我们的 Oracle Fusion 云实例动态调度到 UCM(与您的请求略有不同),但注意到标题中的内容类型区别和用于响应的方法存在以下差异:

headers = {
    "content-type" : "application/soap+xml"
}

response = requests.post(url, data=body, headers=headers)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM