Skip to content

Instantly share code, notes, and snippets.

@koverholt
Last active January 26, 2023 07:29
Show Gist options
  • Save koverholt/bf29bb182a9d862d5d8ae15acd98be92 to your computer and use it in GitHub Desktop.
Save koverholt/bf29bb182a9d862d5d8ae15acd98be92 to your computer and use it in GitHub Desktop.
Sending a SOAP request with Python
import json
import requests
import xmltodict
import pandas as pd
# SOAP URL, payload, and headers
url = "https://hydrometdata.lcra.org/service.asmx"
payload = """<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetFiveDayRainfall xmlns="http://hydrometdata.lcra.org" />
</soap12:Body>
</soap12:Envelope>
"""
headers = {
"SOAPAction": "''",
"Content-Type": "application/soap+xml; charset=utf-8",
}
# Make a POST request
response = requests.request("POST", url, headers=headers, data=payload)
# Convert XML to Pandas Dataframe
decoded_response = response.content.decode("utf-8")
response_json = json.loads(json.dumps(xmltodict.parse(decoded_response)))
df = pd.DataFrame(
response_json["soap:Envelope"]["soap:Body"]["GetFiveDayRainfallResponse"][
"GetFiveDayRainfallResult"
]["clsFiveDayRainfall"]
)
# Print results
pd.set_option("display.max_rows", None)
pd.set_option("display.max_columns", None)
print(df)
openssl_conf = openssl_init
[openssl_init]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
Options = UnsafeLegacyRenegotiation%
OPENSSL_CONF=openssl.cnf python soap.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment