我对 Python 和 AWS 很陌生。
我需要编写一个 AWS Glue 脚本来捕获通过 Python
SOAP
返回的 XML 字符串,然后将此 XML 以 parquet
格式存储在 S3 中。我已经编写了从 SOAP 中提取 XML 的代码,但发现很难在 S3 上以 Parquet 格式捕获和存储 XML。
从
response.text()
创建一个pandas DF是否正确,然后在其上使用to_parquet()
?但我相信这会解析 xml 而不是按原样存储它。另外,由于这是一项胶水工作,我是否需要使用 DynamicFrame 来完成此要求?
如何将 XML 文本响应转换为 Pandas DataFrame?
请指教
import requests
url = "https://www.w3schools.com/xml/tempconvert.asmx"
payload = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope
xmlns:xsi="http://w3.org/2002/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/soap/envelope/">
<soap12:Body>
<CelsiusToFahrenheit xmlns="https://www.w3schools.com/xml/">
<Celsius>20</Celsius>
</CelsiusToFahrenheit>
</soap12:Body>
</soap12:Envelope>"""
headers = {
'Content-Type': 'text/xml; charset=utf-8'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
上面的
response.text
将保存从 SOAP 返回的整个 xml 文本。
谢谢。