Skip to content

Instantly share code, notes, and snippets.

@EgehanGundogdu
Created October 28, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EgehanGundogdu/c5b90615b0b15708c9ab509b30000e39 to your computer and use it in GitHub Desktop.
Save EgehanGundogdu/c5b90615b0b15708c9ab509b30000e39 to your computer and use it in GitHub Desktop.
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