使用Python连接Amadeus SOAP API(http://webservices.amadeus.com/)

2 投票
1 回答
4997 浏览
提问于 2025-04-17 22:27

我刚开始学习Python,也没有使用过Amadeus的API。现在我想通过Amadeus的SOAP API建立连接(链接在这里:http://webservices.amadeus.com/),我有一个.wsdl文件,想用Python发送请求并获取响应。

我查过SOAPpy和suds这些库,也尝试过像这个例子一样使用它们:

从Python发送SOAP请求

但是我不确定请求是否成功发送到服务器,如果发送成功的话,怎么才能获取到响应数据。

请帮帮我,提前谢谢你!

1 个回答

0

如果你为传输库开启了调试日志。

import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.transport.http').setLevel(logging.DEBUG)

那么你在日志输出中会看到类似这样的内容:

DEBUG:suds.transport.http:sending:
URL: http://someurl
HEADERS: {'SOAPAction': '"http://blablabla/identityCheck"', 'Content-Type': 'text/xml; charset=utf-8', 'Content-type': 'text/xml; charset=utf-8', 'Soapaction': '"http://blablabla/blablabla"'}
MESSAGE: <xml......>
DEBUG:suds.transport.http:received:
CODE: 200
HEADERS: {'header1': 'blablabla'}
MESSAGE: <xml......>

另外,你还可以打印出服务结果对象。这是基于我在接口中有一个叫做identityCheck的方法,并且它的输入是customer。

client = Client(wsdl_url, location=endpoint_url)
customer = client.factory.create('customer')
customer.userId = 'A'
customer.password = 'B'

result = client.service.identityCheck(customer)
print result

撰写回答