soco.soap module

Classes for handling SoCo’s basic SOAP requirements.

This module does not handle anything like the full SOAP Specification , but is enough for SoCo’s needs. Sonos uses SOAP for UPnP communications, and for communication with third party music services.

exception soco.soap.SoapFault(faultcode, faultstring, detail=None)[source]

An exception encapsulating a SOAP Fault.

Parameters
  • faultcode (str) – The SOAP faultcode.

  • faultstring (str) – The SOAP faultstring.

  • detail (Element) – The SOAP fault detail, as an ElementTree Element. Defaults to None.

class soco.soap.SoapMessage(endpoint, method, parameters=None, http_headers=None, soap_action=None, soap_header=None, namespace=None, **request_args)[source]

A SOAP Message representing a remote procedure call.

Uses the Requests library for communication with a SOAP server.

Parameters
  • endpoint (str) – The SOAP endpoint URL for this client.

  • method (str) – The name of the method to call.

  • parameters (list) – A list of (name, value) tuples containing the parameters to pass to the method. Default None.

  • http_headers (dict) – A dict in the form {'Header': 'Value,..} containing http headers to use for the http request. Content-type and SOAPACTION headers will be created automatically, so do not include them here. Use this, for example, to set a user-agent.

  • soap_action (str) – The value of the SOAPACTION header. Default ‘None`.

  • soap_header (str) – A string representation of the XML to be used for the SOAP Header. Default None.

  • namespace (str) – The namespace URI to use for the method and parameters. None, by default.

  • **request_args – Other keyword parameters will be passed to the Requests request which is used to handle the http communication. For example, a timeout value can be set.

prepare_headers(http_headers, soap_action)[source]

Prepare the http headers for sending.

Add the SOAPACTION header to the others.

Parameters
  • http_headers (dict) – A dict in the form {'Header': 'Value,..} containing http headers to use for the http request.

  • soap_action (str) – The value of the SOAPACTION header.

Returns

headers including the SOAPACTION header.

Return type

dict

prepare_soap_header(soap_header)[source]

Prepare the SOAP header for sending.

Wraps the soap header in appropriate tags.

Parameters

soap_header (str) – A string representation of the XML to be used for the SOAP Header

Returns

The soap header wrapped in appropriate tags.

Return type

str

prepare_soap_body(method, parameters, namespace)[source]

Prepare the SOAP message body for sending.

Parameters
  • method (str) – The name of the method to call.

  • parameters (list) – A list of (name, value) tuples containing the parameters to pass to the method.

  • namespace (str) – The XML namespace to use for the method.

Returns

A properly formatted SOAP Body.

Return type

str

prepare_soap_envelope(prepared_soap_header, prepared_soap_body)[source]

Prepare the SOAP Envelope for sending.

Parameters
Returns

A prepared SOAP Envelope

Return type

str

prepare()[source]

Prepare the SOAP message for sending to the server.

call()[source]

Call the SOAP method on the server.

Returns

the decapusulated SOAP response from the server, still encoded as utf-8.

Return type

str

Raises