Created
October 28, 2021 10:43
-
-
Save EgehanGundogdu/c5b90615b0b15708c9ab509b30000e39 to your computer and use it in GitHub Desktop.
This file contains 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 requests | |
import xmltodict | |
country_code = input("Country code? : ").upper() | |
country_service_data = { | |
"soap:Envelope": { | |
"@xmlns:soap": "http://schemas.xmlsoap.org/soap/envelope/", | |
"soap:Body": { | |
"CapitalCity": { | |
"@xmlns": "http://www.oorsprong.org/websamples.countryinfo", | |
"sCountryISOCode": {"#text": country_code}, | |
} | |
}, | |
} | |
} | |
xml_dumped_data = xmltodict.unparse(input_dict=country_service_data, encoding="utf-8") | |
headers = {"Content-Type": "text/xml; charset=utf-8;"} | |
url = "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso" | |
raw_resp = requests.post(url=url, data=xml_dumped_data, headers=headers) | |
if raw_resp.status_code != 200: | |
print("Service error.") | |
exit() | |
dumped_response = xmltodict.parse(raw_resp.content) | |
result = dumped_response["soap:Envelope"]["soap:Body"]["m:CapitalCityResponse"][ | |
"m:CapitalCityResult" | |
] | |
if result == "Country not found in the database": | |
print(f"No country matching the {country_code} country code was found.") | |
exit() | |
print(f"Country code {country_code} -> Capital City {result}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment