Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created October 22, 2014 11:17
Show Gist options
  • Save toast38coza/17e2ad6c2cfa2e96b0b1 to your computer and use it in GitHub Desktop.
Save toast38coza/17e2ad6c2cfa2e96b0b1 to your computer and use it in GitHub Desktop.
Call a SOAP Service with plain old requests
import requests
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'text/xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body><ns0:GetWeatherInformation/></ns1:Body>
</SOAP-ENV:Envelope>"""
response = requests.post(url,data=body,headers=headers)
print response.content
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetWeatherInformationResponse xmlns="http://ws.cdyne.com/WeatherWS/"><GetWeatherInformationResult><WeatherDescription><WeatherID>1</WeatherID><Description>Thunder Storms</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>2</WeatherID><Description>Partly Cloudy</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>3</WeatherID><Description>Mostly Cloudy</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/mostlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>4</WeatherID><Description>Sunny</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/sunny.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>5</WeatherID><Description>Rain</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/rain.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>6</WeatherID><Description>Showers</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/showers.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>7</WeatherID><Description>Haze</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/haze.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>9</WeatherID><Description>Partly Sunny</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/mostlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>10</WeatherID><Description>Mostly Sunny</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>11</WeatherID><Description>Clear</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/sunny.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>12</WeatherID><Description>Fair</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>14</WeatherID><Description>Cloudy</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/mostlycloudy.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>15</WeatherID><Description>N/A</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/na.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>17</WeatherID><Description>Drizzle</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/drizzle.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>18</WeatherID><Description>Fog</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/fog.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>20</WeatherID><Description>Flurries</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>21</WeatherID><Description>Snow and Fog</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>26</WeatherID><Description>Blowing Snow and Fog</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>27</WeatherID><Description>Snow</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/snow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>28</WeatherID><Description>Rain and Fog</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/rain.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>29</WeatherID><Description>Blowing Snow</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>32</WeatherID><Description>Light Rain</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/rain.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>33</WeatherID><Description>Heavy Rain</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/rain.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>34</WeatherID><Description>Missing Data</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/na.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>35</WeatherID><Description>Snow, Blowing Snow, and Fog</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/blowingsnow.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>36</WeatherID><Description>Unknown Precipitation</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/na.gif</PictureURL></WeatherDescription><WeatherDescription><WeatherID>37</WeatherID><Description>AM CLOUDS</Description><PictureURL>http://ws.cdyne.com/WeatherWS/Images/partlycloudy.gif</PictureURL></WeatherDescription></GetWeatherInformationResult></GetWeatherInformationResponse></soap:Body></soap:Envelope>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment