Tuesday, June 23, 2009

HOWTO: Install Python Soap Libraries ZSI + SOAPpy + PyXML Under (of all things) Windows XP

Overview
I recently needed do some simple scripting using Python under Windows. The main goal was to test some web service calls (via SOAP). Python lets you put something like this together pretty quickly. Including WSDL processing, business logic, and unit testing.

Adding a SOAP library (ZSI+SOAPpy in this case) under linux (ubuntu or fedora) is also simple since you just install a package from a repo. However, I found that setting is up under Windows to be more of a pain.

Problem
Get ZSI, SOAPpy, fpconst, and PyXML setup for use in SOAP programming under Python 2.6.

The main issue is that one of the dependancies, PyXML, does not have a package for versions of Python > 2.4. This means that it will need to be manually built. The typical setup.py usually does the trick but for PyXML a C module was also included as part of the distro. Compiling modules under Windows requires an open source compiler or Visual Studio 2008. For me, neither are an option. Man I wish I could just use linux :-)

Lets Begin
After you fetch the packages through the Python Website...

Install fpconst
This, I think, is needed by SOAPpy. Fetch fpconst-0.7.2.tar.gz
  1. Under Windows I use WinRAR to extract the setup/temp folder
  2. run: python setup.py build
  3. run: python setup.py install
That is done.

Install PyXML
PyXML is required by SOAPpy and possibly ZSI. The problem you will run into installing it is that there are a few Python extensions that need compiled and unless you have Visual Studio 2008, it will not compile under Python 2.6.

Fortunatally, I discovered that SOAPpy (or ZSI) don't use these extensions so as long as you don't need it yourself you can install it as follows.
  1. Under Windows I use WinRAR to extract the setup/temp folder
  2. run: python setup.py install --force -skip-build
The -skip-build skips the building of the C based extension. Without this parameter you will get an error under windows as it looks for Visual Studio 2008. If you have Visual Studio 2008, you are probably not reading this blog and had no issues installing PyXML :-)

Installing SOAPpy
With PyXML installed, the hard part is over.
  1. Unzip SOAPpy-0.12.0.zip to a setup/temp folder
  2. run: python setup.py build
  3. run: python setup.py install
That is done.

Install ZSI
Now the dependencies are install, ZSI can be installed. This is what you will use for all your SOAP calls. It is pretty well documented and fairly easy to use. The approach is similar to how it is handled in Java or .NET. Install is simple
  1. WinRAR ZSI-2.0.tar.gz to a setup/temp folder
  2. run: python setup.py build
  3. run: python setup.py install
That is done

Does it work?
To test, you will first need to process your web service WSDL file into something Python can work with. The approach is similar to what is done when you add a web service reference in .NET or JAVA. This this case, you use a simple command line utility called wsdl2py. On my windows computer, it is found in C:\Python26\Scripts\ You should find it in a similar place. Assuming that you do not have this script in the path and have not been clever enough to make a batch file, you can run it as follows. CD to the directory where you want your PY files created by the utility to go.

python C:\Python26\Scripts\wsdl2py -bu http://moneycow.sandwich.lan:8888/moneyfinder.asmx?WSDL

There are more parameters, but this command will get you what you need. You may see a few deprecation warnings but they don't hurt anything. In the end, you will get two files.
  • *_services.py
  • *_services_types.py
Or similar. Read the ZSI docs on how to use them. I will try to post a blog soon with an example.

Unknowns
I have not figured out how to get SSL to work with ZSI. If any of you have figured this out, please post me a message. I would love to hear about it. It is not an issue for me now since none of the services I need to consume are Internet exposed. If I get stuck and need to access one, I will just use Java or .NET ;-)

Conclusion
If you have to use Windows and need to do Web Services with Python 2.6, the above steps should get you setup and ready to role. Once you are setup and get your first basic program working, you will find that Python does a good job and the performance is just fine.

5 comments:

R Infimate said...

I have been using ZSI with PyXMl in Python 2.4 with SSL. SSL handling is done transparenly as it uses HTTPlib which has built-in support for limited SSL. In linux i think you will have to compile python with SSL. In Python 2.6 this may not be an issue as more SSL features have been added by default.

Ed said...

all the PyXML downloads i have found are distributed via an exe installation. can you direct me to a download of the module in zip format

uuklanger said...

http://sourceforge.net/projects/pyxml/files/ should have both EXE and tar.gz. The tar.gz version is a "tarrball" which is a unix zip. If you use linux or winrar you can open it.

This is as close to a ZIP as you will get. If you are using Ubuntu or other linux flavors, you should be able to get it via yum or apt repos.

Alex Benke said...

this is great, thank you!

I had some issues whose resolutions I thought I'd share with anyone doing this in case you hit them too.

PyXML 0.8.4 install:
It doesn't seem to create the build/scripts-2.6 folder automatically, so I had to create this manually when I got an error related to it.

SOAPpy install:
I got "SyntaxError: from __future__ imports must occur at the beginning of the file" I had to edit a couple source files (client.py, types.py, server.py) to move the __future__ line to the beginning of the file (up 2 lines).

uuklanger said...

Alex: I had the same issue installing under Windows. To get around it, I simply made changes to the scripts based on the warnings. It affected ~10 files and took 15 minutes. After that the code should work. The small code changes are gentle and have not had any side effects. I run some heavy processing through them currently.

I wish these files would be packaged for Windows as nice as they are for Linux and OSX.

I hope this helps you.