简体   繁体   English

使用 zeep 库在 python 中通过 AWS Lambda 调用 SOAP 网络服务

[英]Calling SOAP webservice through AWS Lambda in python using zeep library

I am trying to make SOAP call using zeep library from AWS ALambda in python.The request requires HTTP Basic Authentication and wsdl is at https protocol so I setter session.verify=false as well.我正在尝试在 python 中使用 AWS ALambda 中的 zeep 库进行 SOAP 调用。请求需要 HTTP 基本身份验证,而 wsdl 使用 https 协议,因此我也设置了session.verify=false Below is my Lambda code.Is this the correct way of making SOAP call from python.下面是我的 Lambda 代码。这是从 python 进行 SOAP 调用的正确方法吗?

def lambda_handler(event, context):
    url = 'wsdl-url'
    session = Session()
    session.verify = False
    session.auth = HTTPBasicAuth('userid', 'password')
    transport = Transport(session=session)
    client = Client(wsdl=url, transport=transport)
    client.transport.session.verify = False
body="""
    <soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/soap/envelope/" xmlns:ver= http:www.xyz.org/Version_4.1_Release" xmlns:cpsm="cpsm">
   <soapenv:Header>
      <ver:XYZMsgHeader MajorVersion="?" MinorVersion="?" Build="?" Branch="?" BuildString="?" UserID="" Pwd="" AppName="?" AppVersion="?" Company="?" DefaultCurrencyCode="?" CSUnits="feet" CoordinateSystemName="?" CoordinateSystemAuthority="?" CoordinateSystemAuthorityCode="?" Datum="?" SessionID="?" PreviousSessionID="?" ObjectsRemaining="?" LastSent="?" RegistrationID="?" MessageID="?" TimeStamp="?" Context="?"/>
   </soapenv:Header>
   <soapenv:Body>
      <ns1:Notification xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="cpsm" xmlns:ns1="http www.xyz.org/Version_4.1_Release">
         <ns1:events>
            <ns1:ABCLog verb="Change">
               <ns1:ABCID>C101</ns1:ABCID>
               <ns1:ABCStateList>
                  <ns1:ABCState verb="Change">
                     <ns1:GMTTime>2019-1020T18:57:33Z</ns1:GMTTime>
                     <ns1:GPS>
                        <ns1:latitude>45.316550303492</ns1:latitude>
                        <ns1:longitude>-122.774259911433</ns1:longitude>
                     </ns1:GPS>
                     <ns1:telemetry>
                        <ns1:speed units="mph">000.000</ns1:speed>
                     </ns1:telemetry>
                  </ns1:ABCState>
               </ns1:ABCStateList>
            </ns1:ABCLog>
         </ns1:events>
      </ns1:Notification>
   </soapenv:Body>
</soapenv:Envelope>"""

    response = client.service.Notification(body)
    print('response: ', response)

But when I run this program in local pycharm ide, getting below error:但是当我在本地 pycharm ide 中运行这个程序时,出现以下错误:

Traceback (most recent call last):
  File "C:/Users/Documents/MyLambda/etl-lambda.py", line 289, in <module>
    lambda_handler(None, None)
  File "C:/Users/Documents/MyLambda/etl-lambda.py", line 82, in lambda_handler
    response = client.service.Notification(body)
  File "C:\Users\AppData\Roaming\Python\Python36\site-packages\zeep\proxy.py", line 45, in __call__
    kwargs,
  File "C:\Users\AppData\Roaming\Python\Python36\site-packages\zeep\xsd\elements\indicators.py", line 229, in render
    element_value = value[name]
TypeError: string indices must be integers

Process finished with exit code 1

Please guide.请指导。

I resolved this using below code:我使用以下代码解决了这个问题:

request_data = \
        {
            'Notification':{
                'events':{
                    'ABCLog':{
                        'ABCID': 'C101',
                        'ABCStateList': {
                            'ABCState':{
                                'GMTTime': '2019-1020T18:57:33Z',
                                'GPS':{
                                    'latitude':'45.316550303492',
                                    'longitude':'-122.774259911433'
                                },
                                'telemetry':{
                                    'speed':'000.000'
                                }
                            }
                        }
                    }
                }
            },
        }

and the called zeep client like below:和被调用的 zeep 客户端如下所示:

response = client.service.Notification(events=[request_data ])

Zeep library takes care of xml formatting. Zeep 库负责 xml 格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python zeep 从具有多个绑定的 Python Soap 客户端访问所有 Web 服务方法 - How to access all Webservice methods from a Python Soap Client with multiple bindings using Python zeep 使用Python 3.5的AWS Lambda的SOAP客户端 - SOAP client for AWS Lambda using Python 3.5 如何使用 Python 的 Zeep 库正确格式化 SOAP 请求? - How do I properly format a SOAP request using Python's Zeep library? 使用zeep库处理SOAP通信时如何处理python中的错误异常 - how to handle fault exception in python while using zeep library to handle SOAP communications "<i>How to add SOAP-ENV:mustUnderstand=&quot;1&quot; in<\/i>如何添加 SOAP-ENV:mustUnderstand=&quot;1&quot;<\/b><wsse:security> <i>header using python zeep library<\/i>使用 python zeep 库的标头<\/b>" - How to add SOAP-ENV:mustUnderstand="1" in <wsse:security> header using python zeep library SOAP 请求 Zeep (Python) - SOAP request with Zeep (Python) 带有Zeep的Python SOAP客户端 - 身份验证 - Python SOAP client with Zeep - authentication 如何使用python zeep通过SOAP以附件形式上传文件 - How to upload a file via SOAP, as an attachment using python zeep SOAP 请求使用 Zeep (Python) “raise XMLParseError: Unexpected element” - SOAP request using Zeep (Python) “raise XMLParseError: Unexpected element ” Python Zeep 客户端使用 Ontario Health EBS MCEDT WSDL(SOAP) 网络服务 - Python Zeep Client to consume Ontario Health EBS MCEDT WSDL(SOAP) webservice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM