Since I am a professional C/C++ programmer, which only means my profession, I can read Python code and modify some trivial changes, even though I don’t know much of Python. But when I want to write new functions, which are not lying in front of my sight, I have no idea how I can write them from scratch and where I can get related information directly. Definitely, I must practice Python in fundamentals first and make my programs streamlined, avoiding waste of time and vulnerable steps.
Luckily, there is Dive Into Python, an online book we can read on the net and on desktop free of charge. It’s great! It’s relatively concise without lengthy explanation and full of interesting suggestions through intuitive examples. How fantastic is that its sentences are easy for programmers who speaks English as a second language, like me. (But I know a book that readers can read easily is difficult to write. It’s a kind of Columbus’ egg.)
Unfortunately, some of URLs in examples are missing, especially the ones on Chapter 12, SOAP Web Services. The temperature function on http://www.xmethods.net/ has disappeared already. Moreover, Google Web Services are no longer available to, at least, new developers, replaced with AJAX Search API implemented by JavaScript literally. So I practiced those examples with Amazon SOAP infrastructure likewise.
>>> from SOAPpy import WSDL
>>> server = WSDL.Proxy('http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl')
>>> results = server.ItemSearch(SubscriptionId="YOUR_ACCESS_KEY_ID", AssociateTag="YOUR_ASSOCIATE_ID", SearchIndex="Music", Keywords="Beatles")
>>> for item in results.Items.Item:
print item.ItemAttributes.Title
The Beatles (The White Album)
Abbey Road
Sgt. Pepper's Lonely Hearts Club Band
Across The Universe [Deluxe Edition]
The Beatles 1
Rubber Soul
Revolver [UK]
A Hard Day's Night
Magical Mystery Tour
Let It Be
>>>
You can get Access Key ID from Amazon Web Services after you sign up. You can also get Associate ID from each locale’s Associates Center, e.g. https://affiliate-program.amazon.com/ for US program, but you can simply use “ws” anonymously. Note that
WSDL documents are available by version and by locale. The following list shows each locale’s WSDL URL for the Version 2008-08-19. You can get the latest version’s WSDL without version subdirectory string from its path.
US: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/AWSECommerceService.wsdl
UK: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/UK/AWSECommerceService.wsdl
DE: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/DE/AWSECommerceService.wsdl
JP: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/JP/AWSECommerceService.wsdl
FR: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/FR/AWSECommerceService.wsdl
CA: http://ecs.amazonaws.com/AWSECommerceService/2008-08-19/CA/AWSECommerceService.wsdl
I suppose SOAPpy, a Python SOAP module introduced in this book, is also outdated already. There is Zolera SOAP Infrastructure, or ZSI module supported by the same project primarily now. So I’m going to learn more yet about ZSI and its bundled tool wsdl2py. To be honest, I’m using pyAWS for my Amazon Plugin now. But I’ll consider replacing it with one of the SOAP modules and adding more functionality to the plugin, after going through the SOAP modules thoroughly.