Welcome, guest | Sign In | My Account | Store | Cart

This is a simple example of web service usage (here: currency exchange rate service from xmethods) in python via a http proxy. Proxy information is taken from the environment.

Python, 26 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from SOAPpy import SOAPProxy
import os, sys
# python sample code for the Currency Exchange service


if len(sys.argv)<>3:
    print "usage: %s germany sweden\n\tyou may try other countries"%(sys.argv[0])
    sys.exit(-1)


# in some intranets an issue: how to use a web proxy for WS. Here
# we assume a set environment variable 'http_proxy'.·
# This is common in unix environments. SOAPpy does not like
# a leading 'http://'
if os.environ.has_key("http_proxy"):·
    my_http_proxy=os.environ["http_proxy"].replace("http://","")
else:
     my_http_proxy=None

url = 'http://services.xmethods.net:80/soap'
n   = 'urn:xmethods-CurrencyExchange'


server = SOAPProxy(url, namespace=n, http_proxy=my_http_proxy)

print sys.argv[1], sys.argv[2], server.getRate(sys.argv[1], sys.argv[2])

SOAPpy makes not use of http_proxy from the environment directly and needs a specific format to work.

Created by Sebastian Schneckener on Mon, 13 Feb 2006 (PSF)
Python recipes (4591)
Sebastian Schneckener's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks