簡體   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