Reputation: 856
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. Below is my Lambda code.Is this the correct way of making SOAP call from python.
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:
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.
Upvotes: 1
Views: 3490
Reputation: 856
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:
response = client.service.Notification(events=[request_data ])
Zeep library takes care of xml formatting.
Upvotes: 1