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}")