Milinda Pathirage’s Blog

Computers are fascinating machines, but they’re mostly a reflection of the people using them

Consuming Web Services in Python

August 5th, 2008 · No Comments · python, wsf-python, wso2

Here is a sample client that I write to test WSF/Python 1.0.0alpha implementation. It talks to yahoo REST search API using WSF/Python.
#!/usr/bin/env python
 
import wso2.wsf
 
LOG_DIR = '/tmp/'
LOG_LEVEL = 4
WSFC_HOME = '/home/milinda/wsfc'
END_POINT = 'http://search.yahooapis.com/WebSearchService/V1/webSearch'
 
if __name__ == '__main__':
    message = """
 
        ApacheRestDemo
        Sri Lanka
<form>
    </form>
 
   """
    try:
        client = wso2.wsf.WSClient({
            'to':END_POINT,
            'WSF_LOG_DIR':LOG_DIR,
            'WSF_LOG_LEVEL':LOG_LEVEL,
            'WSFC_HOME':WSFC_HOME,
            'use_soap':'False',
            'http_method':'GET'
            })
 
        print 'Sending: ' + message
 
        response = client.request(message)
 
        print 'Respose: ' + response + '\n'
    except wso2.wsf.WSFault, e:
        print 'Exception occurred:'
        print e
Here is another sample which invokes echo sample Web Service which comes with Apache Axis2/C Web Services engine distributions.
import wso2.wsf
 
LOG_DIR = '/tmp/'
LOG_LEVEL = 4
WSFC_HOME = '/home/milinda/wso2/wsfc/deploy'
END_POINT = 'http://localhost:9090/axis2/services/echo/echoString'
 
if __name__ == '__main__':
    message = """
 
        Hello World!
 
    """
    try:
        client = wso2.wsf.WSClient({
            'to':END_POINT,
            'WSF_LOG_DIR':LOG_DIR,
            'WSF_LOG_LEVEL':LOG_LEVEL,
            'WSFC_HOME':WSFC_HOME,
            })
 
        print 'Sending: ' + message
 
        response = client.request(message)
 
        if response is not None:
            print 'Respose: ' + response + '\n'
        else:
            print 'Error occurred!'
    except wso2.wsf.WSFault, e:
        print 'Exception occurred:'
        print e
You can download WSF/Python 1.0.0alpha from http://wso2.org/downloads/wsf/python. Instruction for installing WSF/Python is in README.INSTALL file. Features which will support in near future:
  • WSDL support for client side.
  • Web Services Security support for client side.
  • Web Services in Python.
Sphere: Related Content

Related posts brought to you by Yet Another Related Posts Plugin.

Tags:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment