我是python新手。我需要从Oracle融合云获取数据。我想融合云实例上运行的BI出版商报告使用SOAP API调用获取数据到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。<请求模块/strong>:
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模块/strong>
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)