WEB开发网
开发学院软件开发Python Python Web 服务开发者: 现实世界,第二部分 阅读

Python Web 服务开发者: 现实世界,第二部分

 2007-03-29 12:13:08 来源:WEB开发网   
核心提示: 清单 2. amazon_soap_test.py —— 用于测试 Amazon Web 服务 API 的简单 Python 代码。#!/usr/bin/pythonimport SOAPpyurl = 'http://soap.amazon.com/sch

清单 2. amazon_soap_test.py —— 用于测试 Amazon Web 服务 API 的简单 Python 代码。     
#!/usr/bin/python
import SOAPpy
url = 'http://soap.amazon.com/schemas3/AmazonWebServices.wsdl'
proxy = SOAPpy.WSDL.Proxy(url)
# show methods retrieved from WSDL
print '%d methods in WSDL:' % len(proxy.methods) + '\n'
for key in proxy.methods.keys():
  print key
print
# search request
_query = 'spotted owl'
request = { 'keyword': _query,
      'page':   '1',
      'mode':   'books',
      'tag':   '',
      'type':   'lite',
      'devtag':  'INSERT YOUR TOKEN HERE' }
results = proxy.KeywordSearchRequest(request)
# display results
print 'Amazon.com search for " ' + _query + ' "\n'
print 'total pages of results (max 10 per page): ' + str(results.TotalPages)
print 'total results: ' + str(results.TotalResults) + '\n'
# only show first result here
if (results.TotalResults > 0):
  print 'displaying first result (of %s):\n' %results.TotalResults
  details = results.Details[0]
  
  # we must use the _keys() method of SOAPpy Types.py for arrayType
  for key in details._keys():
    print key + ': ' + details[key]
  print
      

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Python Web 服务

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接