Forum Discussion
Oracle Fusion > BI Publisher to Power BI via Python: wait for connection establishing
- 3 years ago
you won't believe , but the issue was in redundant blanks after the last row.
So this work well.
As compensation for your time, I provide here the working code. Perhaps it is helpfull
import requests
import lxml.etree as ET
import pandas as pd
import base64
import re# Set up the SOAP request
url = 'https://myhost.oraclecloud.com:Port/xmlpserver/services/ExternalReportWSSService'
headers = {
'Content-Type': 'application/soap+xml;charset=UTF-8'
}
data = '''<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:reportAbsolutePath>./.../.../MyReport.xdo</pub:reportAbsolutePath>
<pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
</pub:reportRequest>
</pub:runReport>
</soap:Body>
</soap:Envelope>'''# Set up the basic authentication credentials
user = 'myuser'
password = 'mypwd'# Send the SOAP request with basic authentication
response = requests.post(url, headers=headers, data=data, auth=(user, password))# Parsing XML
root = ET.fromstring(response.content)# This code uses Python's base64.b64decode() method to decode the Base64-encoded data.
# The resulting report_bytes variable contains the original binary data.
report_bytes = base64.b64decode(root.xpath('//*[local-name()="reportBytes"]')[0].text)
report_bytes = report_bytes.decode('utf-8')# Removing the first line <?xml version="1.0" encoding="UTF-8"?>
report_bytes = re.sub(r'^<\?xml.*\?>', '', report_bytes)# Parsing XML (again)
root = ET.fromstring(report_bytes)# extract column names
columns = [child.tag for child in root.find('G_1').iter()]# create an empty data frame
df = pd.DataFrame(columns=columns)#### populate the data frame #####
# create an empty list to store the data frames
df_list = []
for g in root.findall('G_1'):
row = {}
for child in g.iter():
row[child.tag] = child.text
df_list.append(pd.DataFrame(row, index=[0]))# concatenate the data frames into one
df = pd.concat(df_list, ignore_index=True)
df = df.drop('G_1', axis=1)
print(df)
you won't believe , but the issue was in redundant blanks after the last row.
So this work well.
As compensation for your time, I provide here the working code. Perhaps it is helpfull
import requests
import lxml.etree as ET
import pandas as pd
import base64
import re
# Set up the SOAP request
url = 'https://myhost.oraclecloud.com:Port/xmlpserver/services/ExternalReportWSSService'
headers = {
'Content-Type': 'application/soap+xml;charset=UTF-8'
}
data = '''<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:reportAbsolutePath>./.../.../MyReport.xdo</pub:reportAbsolutePath>
<pub:sizeOfDataChunkDownload>-1</pub:sizeOfDataChunkDownload>
</pub:reportRequest>
</pub:runReport>
</soap:Body>
</soap:Envelope>'''
# Set up the basic authentication credentials
user = 'myuser'
password = 'mypwd'
# Send the SOAP request with basic authentication
response = requests.post(url, headers=headers, data=data, auth=(user, password))
# Parsing XML
root = ET.fromstring(response.content)
# This code uses Python's base64.b64decode() method to decode the Base64-encoded data.
# The resulting report_bytes variable contains the original binary data.
report_bytes = base64.b64decode(root.xpath('//*[local-name()="reportBytes"]')[0].text)
report_bytes = report_bytes.decode('utf-8')
# Removing the first line <?xml version="1.0" encoding="UTF-8"?>
report_bytes = re.sub(r'^<\?xml.*\?>', '', report_bytes)
# Parsing XML (again)
root = ET.fromstring(report_bytes)
# extract column names
columns = [child.tag for child in root.find('G_1').iter()]
# create an empty data frame
df = pd.DataFrame(columns=columns)
#### populate the data frame #####
# create an empty list to store the data frames
df_list = []
for g in root.findall('G_1'):
row = {}
for child in g.iter():
row[child.tag] = child.text
df_list.append(pd.DataFrame(row, index=[0]))
# concatenate the data frames into one
df = pd.concat(df_list, ignore_index=True)
df = df.drop('G_1', axis=1)
print(df)