[英]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.