-
-
Save sansal54/f50c863ff2efb3e4e8717144c1d4757f to your computer and use it in GitHub Desktop.
Sending a SOAP request with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openssl_conf = openssl_init | |
[openssl_init] | |
ssl_conf = ssl_sect | |
[ssl_sect] | |
system_default = system_default_sect | |
[system_default_sect] | |
Options = UnsafeLegacyRenegotiation% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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