spacer
spacer

Suds

Installation

The Suds module can be installed by:

  1. Using an operating system package manager install/update the appropriate package. For example:
    1. On Debain Linux or Debain based Linux distributions (e.g. Bio-Linux, Linux Mint or Ubuntu), install the python-suds package:
      sudo apt-get install python-suds
    2. On RedHat based Linux distributions (e.g. CentOS, Fedora, Red Hat Enterprise Linux, and Scientific Linux) install the python-suds package:
      yum install python-suds
    3. If using MacPorts on OS X install the py-suds package.
    4. If using Fink on OS X install the Suds package corresponding to your Python version, for example suds-py27 for Python 2.7.
  2. Download the Suds distribution and install manually, see Installing Python Modules:

SOAP Message Trace

It is useful when debugging a client to be able to see the actual SOAP messages exchanged. Suds provides a loggng option which can be used to enable output of these messages:

import logging
 
# Send log messages to console
logging.basicConfig(level=logging.INFO)
# Set Suds logging level to debug, outputs the SOAP messages.
logging.getLogger('suds.client').setLevel(logging.DEBUG)

Proxies

In some environments it is necessary to configure a proxy before a client can connect to external services. To use a HTTP proxy with Suds:

proxyOpts = {'http': 'proxy.example.com:8080'}
client.set_options(proxy=proxyOpts)

To support the use of the http_proxy or HTTP_proxy environment variables to set the proxy information, which typically include the protocol prefix, the following could be used:

# Configure HTTP proxy from OS environment (e.g. http_proxy="http://proxy.example.com:8080")
import os
proxyOpts = dict()
if os.environ.has_key('http_proxy'):
    proxyOpts['http'] = os.environ['http_proxy'].replace('http://', '')
elif os.environ.has_key('HTTP_PROXY'):
    proxyOpts['http'] = os.environ['HTTP_PROXY'].replace('http://', '')
if 'http' in proxyOpts:
    client.set_options(proxy=proxyOpts)

User-Agent

HTTP clients usually provide information about what they are, this allows services to handle specific clients differently if necessary, and gives service providers information about how their services are being used. By default Suds does not set the HTTP User-Agent header (see RFC2616 section 14.43), instead using the default setting from urllib2 Python-urllib/2.5 where the version number (2.5) is the version of Python. If additional identification of the client is required a more specific product token (see RFC2616 section 3.8) should be added to the beginning of the User-Agent string:

# Modify the user-agent to add a more specific prefix (see RFC2616 section 14.43)
import platform
import suds
import urllib2
 
# User-agent string to use:
#   Example-Client/1.0 suds/0.3.9 (Python 2.5.2; Linux) Python-urllib/2.5
userAgent = 'Example-Client/1.0 suds/%s (Python %s; %s) Python-urllib/%s' % (
    suds.__version__, platform.python_version(),
    platform.system(), urllib2.__version__
)
 
# Set HTTP headers
httpHeaders = {'User-agent': userAgent}
dbfetchSrv.set_options(headers=httpHeaders)

Note: while the HTTP specification does not define a limit on the size of HTTP headers, web server implementations often do limit the maximum size of an HTTP header to 8KB or 16KB. If the server limit for an HTTP header is exceeded a “400 Bad Request” will be returned by the server.

Sample Clients

Most SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Python some of the clients are based on SUDS.

Document/literal SOAP

 
tutorials/06_programming/python/soap/suds.txt · Last modified: 2014/03/27 11:54 by hpm
spacer
spacer