错误:在EbxmlMessage中指定的操作不存在

时间:2018-10-22 20:18:52

标签: python soap sabre zeep

我正在尝试使用Python和zeep模块来访问Saber SOAP API。我目前无法创建会话,因为我不断收到此错误:

Fault: Action specified in EbxmlMessage does not exist.

我一直在Stack Overflow的其他地方寻找解决方案,在少数示例中,这是因为开发人员使用了错误的操作名称。此处似乎并非如此,因为文档称该动作称为“ SessionCreateRQ”,而且我已经能够在SoapUI中成功创建会话(使用SessionCreateRQ)。

这是我的代码:

from requests import Session
from zeep import Client
from zeep import xsd 
from zeep.transports import Transport
from zeep.wsse.username import UsernameToken

s = Session()
s.proxies = {'http': "http://proxy:proxy@proxy:port",
             'https': "https://proxy:proxy@proxy:port"}



wsdl = 'http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl'

client = Client(wsdl=wsdl, transport=Transport(session=s))  

# Create the header XML structure
header = xsd.Element('MessageHeader', xsd.ComplexType([
                        xsd.Element('From', xsd.ComplexType([
                                        xsd.Element('PartyId', xsd.String())
                                        ])
                                    ),
                        xsd.Element('To', xsd.ComplexType([
                                        xsd.Element('PartyId', xsd.String())
                                        ])
                                    ),
                        xsd.Element('CPAId', xsd.String()),
                        xsd.Element('ConversationID', xsd.String()),
                        xsd.Element('Service', xsd.String()),
                        xsd.Element('Action', xsd.String()),
                        xsd.Element('MessageData', xsd.ComplexType([
                                xsd.Element('MessageID', xsd.String()),
                                xsd.Element('Timestamp', xsd.String()),
                                ])),
                        ])
                     )

# Apply the header values
header_value = header(
                    From={'PartyId': xsd.SkipValue},
                      To={'PartyId': xsd.SkipValue},
                      CPAId='IPCC',
                      ConversationID='ABC123@clientURL.com',
                      Service='Session',
                      Action='SessionCreateRQ',
                      MessageData={'MessageID': '1234',
                                   'Timestamp': '2018-10-22T16:30:00Z'}
                      )

# Call the method
client.service.SessionCreateRQ(POS='IPCC', _soapheaders=[header_value])

有什么主意可以解决这个问题吗?

更新:我已经按照Imran的建议更新了XML结构,但仍然收到“在EbxmlMessage中指定的操作不存在:

header = xsd.Element('Header', xsd.ComplexType([
        xsd.Element('MessageHeader', xsd.ComplexType([
                    xsd.Element('From', xsd.ComplexType([
                                    xsd.Element('PartyId', xsd.String())
                                    ])
                                ),
                    xsd.Element('To', xsd.ComplexType([
                                    xsd.Element('PartyId', xsd.String())
                                    ])
                                ),
                    xsd.Element('CPAId', xsd.String()),
                    xsd.Element('ConversationID', xsd.String()),
                    xsd.Element('Service', xsd.String()),
                    xsd.Element('Action', xsd.String()),
                    xsd.Element('MessageData', xsd.ComplexType([
                            xsd.Element('MessageID', xsd.String()),
                            xsd.Element('Timestamp', xsd.String()),
                            ])),
                    ])
                 ),
        xsd.Element('Security', xsd.ComplexType([
                        xsd.Element('UsernameToken', xsd.ComplexType([
                            xsd.Element('Username', xsd.String()),
                            xsd.Element('Password', xsd.String()),
                            xsd.Element('Organization', xsd.String()),
                            xsd.Element('Domain', xsd.String()),
                                                                    ]))
                                                ])
                  )

]))

# Apply the header values
header_values = header(MessageHeader={'From':{'PartyId': xsd.Nil},
                                      'To': {'PartyId': xsd.Nil},
                                      'CPAId': '1234',
                                      'ConversationID': '1234',
                                      'Service': 'SessionCreateRQ',
                                      'Action': 'SessionCreateRQ',
                                      'MessageData': {'MessageID': '1234',
                                                      'Timestamp': '2018-08-10T09:58:31Z'}},
                        Security={'UsernameToken': {'Username': 'username',
                                                    'Password': 'password',
                                                    'Organization': 'IPCC',
                                                    'Domain': 'AA'}})

client.service.SessionCreateRQ(POS='IPCC', _soapheaders=[header_value])

1 个答案:

答案 0 :(得分:0)

Service元素应与Action元素内的值匹配。或者将Service元素保留为空

<eb:Service>SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>

OR

<eb:Service />
<eb:Action>SessionCreateRQ</eb:Action>

https://developer.sabre.com/resources/getting_started_with_sabre_apis/sabre_apis_101/how_to_guides/soap_apis_request_format

此外,要创建会话,您将需要在Header下传递凭据

<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
    <wsse:UsernameToken>
        <wsse:Username>USER_NAME</wsse:Username>
        <wsse:Password>PASSWORD</wsse:Password>
        <Organization>IPCC</Organization>
        <Domain>DEFAULT</Domain>
    </wsse:UsernameToken>
</wsse:Security>

最终XML生成

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader">
            <eb:From>
                <eb:PartyId>app</eb:PartyId>
            </eb:From>
            <eb:To>
                <eb:PartyId>webservices.sabre.com</eb:PartyId>
            </eb:To>
            <eb:CPAId>IPCC</eb:CPAId>
            <eb:ConversationId>4de1db4e-0e4c-48d3-8a73-4923ff8d2c5c</eb:ConversationId>
            <eb:Service />
            <eb:Action>SessionCreateRQ</eb:Action>
            <eb:MessageData>
                <eb:MessageId>e0d3923a-e5d1-40f9-9629-3618c2f62a4d</eb:MessageId>
                <eb:Timestamp>2018-11-29T17:07:41Z</eb:Timestamp>
            </eb:MessageData>
        </eb:MessageHeader>
        <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
            <wsse:UsernameToken>
                <wsse:Username>USER_NAME</wsse:Username>
                <wsse:Password>PASSWORD</wsse:Password>
                <Organization>IPCC</Organization>
                <Domain>DEFAULT</Domain>
            </wsse:UsernameToken>
        </wsse:Security>
    </soap:Header>
    <soap:Body>
        <SessionCreateRQ xmlns="http://www.opentravel.org/OTA/2002/11">
            <POS>
                <Source PseudoCityCode="IPCC" />
            </POS>
        </SessionCreateRQ>
    </soap:Body>
</soap:Envelope>