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.
- 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
andSOAPACTION
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.
- prepare_soap_header(soap_header)[source]
Prepare the SOAP header for sending.
Wraps the soap header in appropriate tags.
- prepare_soap_body(method, parameters, namespace)[source]
Prepare the SOAP message body for sending.
- prepare_soap_envelope(prepared_soap_header, prepared_soap_body)[source]
Prepare the SOAP Envelope for sending.
- Parameters
prepared_soap_header (str) – A SOAP Header prepared by
prepare_soap_header
prepared_soap_body (str) – A SOAP Body prepared by
prepare_soap_body
- Returns
A prepared SOAP Envelope
- Return type
- call()[source]
Call the SOAP method on the server.
- Returns
the decapusulated SOAP response from the server, still encoded as utf-8.
- Return type
- Raises
SoapFault – if a SOAP error occurs.
HTTPError – if an http error occurs.
xml.etree.ElementTree.ParseError – If the response cannot be parsed as XML