cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1261
Views
10
Helpful
4
Replies

Need assistance fetching data returned by Zeep

William Bryant
Level 1
Level 1

Hello all

I'm attempting to fetch some information from a executeSQLQuery SOAP Command and I'm not able to return the text values in the xml elements that are returned.

 

All I'm getting is output like this: <Element pkid at 0x1cf373590c0>

Specifically I would need to return the text contained in <pkid>6adf790c-6913-7a69-5d42-efc5ddc10cdc</pkid> or any other element nested in <return><row></row></return>

 

I'm using the axlZeep.py listed on devnet as a reference and its using the following to return data from the getUser command:

 
try:
    user_resp = service.getUser(**user_data)
except Fault as err:
    print("\nZeep error: {0}".format(err))
else:
    print("\ngetUser response:\n")
    print(user_resp,"\n\n")
    fname = user_resp['return']['user']['firstName']
    lname = user_resp['return']['user']['lastName']
    print( 'Parsed user info: {0} {1}'.format( fname, lname ) )
My Code is :
 
from lxml import etree
import xmltodict
from zeep import Client, Settings, Plugin
from zeep.transports import Transport
from zeep.cache import SqliteCache
from zeep.exceptions import Fault
from zeep.helpers import serialize_object
from requests import Session
from requests.auth import HTTPBasicAuth
import sys
import urllib3
import os

WSDL_FILE = 'schema/AXLAPI.wsdl'

DEBUG = True

CERT = 'tomcat.pem'

f = open('config.xml','r')
xml_config = f.read()
xml_dict = xmltodict.parse(xml_config)
xml_config_data = dict(xml_dict['settings'])

class MyLoggingPlugin( Plugin ):

    def egress( self, envelope, http_headers, operation, binding_options ):

        # Format the request body as pretty printed XML
        xml = etree.tostring( envelope, pretty_print = True, encoding = 'unicode')

        print( f'\nRequest\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}' )

    def ingress( self, envelope, http_headers, operation ):

        # Format the response body as pretty printed XML
        xml = etree.tostring( envelope, pretty_print = True, encoding = 'unicode')

        print( f'\nResponse\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}' )

session = Session()
session.verify = CERT
session.verify = False
session.auth = HTTPBasicAuth(xml_config_data['ccmaxluser'],xml_config_data['ccmaxlpass'])
transport = Transport( session = session, timeout = 10 )
settings = Settings( strict=False, xml_huge_tree=True )
plugin = [ MyLoggingPlugin() ] if DEBUG else [ ]
client = Client( WSDL_FILE, settings = settings, transport = transport, plugins = plugin )
service = client.create_service( '{http://www.cisco.com/AXLAPIService/}AXLAPIBinding', f'https://{xml_config_data["ccmpub"]}:8443/axl/' )
template_list_query = {
    'sql' : 'select * from device where name like \'NCDV-TATOOL-AgentCSF%\''
}
try:
    template_query_resp = service.executeSQLQuery(**template_list_query)
except Fault as err:
    print("\nZeep error: {0}".format(err))
else:
    print(template_query_resp)
    print(template_query_resp['row']['return']['pkid'])
 
 
The XML being returned from the server is:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:executeSQLQueryResponse xmlns:ns="http://www.cisco.com/AXL/API/12.5">
      <return>
        <row>
          <pkid>6adf790c-6913-7a69-5d42-efc5ddc10cdc</pkid>
          <name>NCDV-TATOOL-AgentCSF</name>
          <description>Agent Softphone for Department Agent Name</description>
          <tkmodel>503</tkmodel>
          <tkdeviceprotocol>11</tkdeviceprotocol>
          <tkprotocolside>1</tkprotocolside>
          <specialloadinformation/>
          <fkdevicepool>cb49be07-fbb4-0356-33b0-a95bc904b725</fkdevicepool>
          <fkphonetemplate>8e1a10fa-a52c-4435-a4ec-540d266c8c37</fkphonetemplate>
          <fkcallingsearchspace>7c432750-8568-45cc-2dd7-cd8b12fd39e4</fkcallingsearchspace>
          <ctiid>94</ctiid>
          <tkclass>253</tkclass>
          <fkprocessnode/>
          <defaultdtmfcapability>0</defaultdtmfcapability>
          <fklocation>29c5c1c4-8871-4d1e-8394-0b9181e8c54d</fklocation>
          <tkproduct>390</tkproduct>
          <dialplanwizardgenid/>
          <deviceleveltraceflag>f</deviceleveltraceflag>
          <fkenduser>33d23d46-d287-deeb-0f84-0696fdcd58af</fkenduser>
          <allowhotelingflag>f</allowhotelingflag>
          <tkdeviceprofile>4</tkdeviceprofile>
          <ikdevice_defaultprofile/>
          <fkmediaresourcelist/>
          <userholdmohaudiosourceid/>
          <networkholdmohaudiosourceid/>
          <unit>0</unit>
          <subunit>0</subunit>
          <tkcountry/>
          <tkuserlocale/>
          <tkproduct_base/>
          <fkcallingsearchspace_aar/>
          <fkaarneighborhood/>
          <fksoftkeytemplate/>
          <retryvideocallasaudio>t</retryvideocallasaudio>
          <routelistenabled>f</routelistenabled>
          <fkcallmanagergroup/>
          <tkstatus_mlppindicationstatus>0</tkstatus_mlppindicationstatus>
          <tkpreemption>0</tkpreemption>
          <tkstatus_builtinbridge>1</tkstatus_builtinbridge>
          <mtprequired>f</mtprequired>
          <tkqsig>4</tkqsig>
          <tkpacketcapturemode>0</tkpacketcapturemode>
          <packetcaptureduration>0</packetcaptureduration>
          <authenticationstring/>
          <tkcertificatestatus>1</tkcertificatestatus>
          <upgradefinishtime/>
          <fkmlppdomain/>
          <transmitutf8>f</transmitutf8>
          <ignorepi>f</ignorepi>
          <tknetworklocation>2</tknetworklocation>
          <v150modemrelaycapable>f</v150modemrelaycapable>
          <tkcertificateoperation>1</tkcertificateoperation>
          <fksecurityprofile>c6085e14-a32c-4c5e-a3d1-8daf60d81594</fksecurityprofile>
          <fkdialrules/>
          <fkcallingsearchspace_reroute/>
          <fkcallingsearchspace_refer/>
          <unattended_port>f</unattended_port>
          <tkdtmfsignaling>1</tkdtmfsignaling>
          <requiredtmfreception>f</requiredtmfreception>
          <publickey/>
          <fksipprofile>fcbc7581-4d8d-48f3-917e-00b09fb39213</fksipprofile>
          <rfc2833disabled>f</rfc2833disabled>
          <allowcticontrolflag>t</allowcticontrolflag>
          <datetimeinserted/>
          <sshpassword/>
          <sshuserid/>
          <fkcallingsearchspace_restrict/>
          <fkmatrix_presence>ad243d17-98b4-4118-8feb-5ff2e1b781ac</fkmatrix_presence>
          <fkcommonphoneconfig>ac243d17-98b4-4118-8feb-5ff2e1b781ac</fkcommonphoneconfig>
          <tkkeyauthority>0</tkkeyauthority>
          <tksipcodec_mtppreferredorigcodec>1</tksipcodec_mtppreferredorigcodec>
          <md5hash/>
          <srtpallowed>f</srtpallowed>
          <isstandard>f</isstandard>
          <resettoggle>f</resettoggle>
          <tkreset>2</tkreset>
          <versionstamp>0000000000-c7a6c673-7479-46b0-839e-014d3d093963</versionstamp>
          <fkcommondeviceconfig>07f0783d-0b53-896b-d9a5-fbfbc4476970</fkcommondeviceconfig>
          <huntlistforvm>f</huntlistforvm>
          <remotedevice>f</remotedevice>
          <tkstatus_devicemobilitymode>2</tkstatus_devicemobilitymode>
          <dndtimeout>0</dndtimeout>
          <tkdndoption>0</tkdndoption>
          <tkringsetting_dnd/>
          <isdualmode>f</isdualmode>
          <fkcallingsearchspace_cgpntransform/>
          <fkenduser_mobility/>
          <tkoutboundcallrollover>0</tkoutboundcallrollover>
          <tkphonepersonalization>3</tkphonepersonalization>
          <tkstatus_joinacrosslines>0</tkstatus_joinacrosslines>
          <tkbarge>0</tkbarge>
          <tkstatus_usetrustedrelaypoint>2</tkstatus_usetrustedrelaypoint>
          <istrustedrelaypoint>f</istrustedrelaypoint>
          <srtpfallbackallowed>f</srtpfallbackallowed>
          <ispaienabled>t</ispaienabled>
          <isrpidenabled>t</isrpidenabled>
          <tksipprivacy>0</tksipprivacy>
          <tksipassertedtype>0</tksipassertedtype>
          <fkcallingsearchspace_cdpntransform/>
          <usedevicepoolcdpntransformcss>t</usedevicepoolcdpntransformcss>
          <nationalprefix>Default</nationalprefix>
          <internationalprefix>Default</internationalprefix>
          <unknownprefix>Default</unknownprefix>
          <subscriberprefix>Default</subscriberprefix>
          <usedevicepoolcgpntransformcss>t</usedevicepoolcgpntransformcss>
          <ikdevice_primaryphone/>
          <tkstatus_audiblealertingidle>2</tkstatus_audiblealertingidle>
          <tkstatus_audiblealertingbusy>2</tkstatus_audiblealertingbusy>
          <isactive>t</isactive>
          <tkphoneservicedisplay>3</tkphoneservicedisplay>
          <isprotected>f</isprotected>
          <fkmobilesmartclientprofile/>
          <tkstatus_alwaysuseprimeline>2</tkstatus_alwaysuseprimeline>
          <tkstatus_alwaysuseprimelineforvm>2</tkstatus_alwaysuseprimelineforvm>
          <callednationalprefix>Default</callednationalprefix>
          <calledinternationalprefix>Default</calledinternationalprefix>
          <calledunknownprefix>Default</calledunknownprefix>
          <calledsubscriberprefix>Default</calledsubscriberprefix>
          <callednationalstripdigits/>
          <calledinternationalstripdigits/>
          <calledunknownstripdigits/>
          <calledsubscriberstripdigits/>
          <fkcallingsearchspace_callednational/>
          <fkcallingsearchspace_calledintl/>
          <fkcallingsearchspace_calledunknown/>
          <fkcallingsearchspace_calledsubscriber/>
          <hotlinedevice>f</hotlinedevice>
          <fkgeolocation/>
          <fkgeolocationfilter_lp/>
          <sendgeolocation>f</sendgeolocation>
          <nationalstripdigits/>
          <internationalstripdigits/>
          <unknownstripdigits/>
          <subscriberstripdigits/>
          <fkcallingsearchspace_cgpnnational/>
          <fkcallingsearchspace_cgpnintl/>
          <fkcallingsearchspace_cgpnunknown/>
          <fkcallingsearchspace_cgpnsubscriber/>
          <usedevicepoolcalledcssnatl>t</usedevicepoolcalledcssnatl>
          <usedevicepoolcalledcssintl>t</usedevicepoolcalledcssintl>
          <usedevicepoolcalledcssunkn>t</usedevicepoolcalledcssunkn>
          <usedevicepoolcalledcsssubs>t</usedevicepoolcalledcsssubs>
          <pstnaccess>f</pstnaccess>
          <fkvipre164transformation/>
          <usedevicepoolcgpntransformcssnatl>t</usedevicepoolcgpntransformcssnatl>
          <usedevicepoolcgpntransformcssintl>t</usedevicepoolcgpntransformcssintl>
          <usedevicepoolcgpntransformcssunkn>t</usedevicepoolcgpntransformcssunkn>
          <usedevicepoolcgpntransformcsssubs>t</usedevicepoolcgpntransformcsssubs>
          <fkfeaturecontrolpolicy/>
          <runonallnodes>f</runonallnodes>
          <enableixchannel>f</enableixchannel>
          <tkdevicetrustmode>0</tkdevicetrustmode>
          <usedevicepoolrdntransformcss>t</usedevicepoolrdntransformcss>
          <fkcallingsearchspace_rdntransform/>
          <enablebfcp>f</enablebfcp>
          <requirecerlocation>f</requirecerlocation>
          <usedevicepoolcgpningressdn>t</usedevicepoolcgpningressdn>
          <fkcallingsearchspace_cgpningressdn/>
          <earlyoffersupportforvoicecall>f</earlyoffersupportforvoicecall>
          <enablegatewayrecordingqsig>f</enablegatewayrecordingqsig>
          <calreference>-1</calreference>
          <tkcalmode/>
          <ndescription>Agent Softphone for Department Agent Name</ndescription>
          <msisdn/>
          <fkwirelesslanprofilegroup/>
          <enablecallroutingtordwhennoneisactive>f</enablecallroutingtordwhennoneisactive>
          <fkwifihotspotprofile/>
          <allowcfbcontrolofcallsecurityicon>f</allowcfbcontrolofcallsecurityicon>
          <fkelingroup/>
          <ecpublickeycurve/>
          <lscvaliduntil>0</lscvaliduntil>
          <lscissuername/>
          <lscissuervaliduntil>0</lscissuervaliduntil>
          <tktrustreceivedidentity>0</tktrustreceivedidentity>
          <enableactivationid>f</enableactivationid>
          <fkmraservicedomain/>
          <allowmramode>f</allowmramode>
          <isdevicemigrated>f</isdevicemigrated>
        </row>
        <row>
          <pkid>0cc1297a-6f78-0d7a-d96c-99ac066c6fd5</pkid>
          <name>NCDV-TATOOL-AgentCSF-1</name>
          <description>Agent Softphone for Department Agent Name</description>
          <tkmodel>503</tkmodel>
          <tkdeviceprotocol>11</tkdeviceprotocol>
          <tkprotocolside>1</tkprotocolside>
          <specialloadinformation/>
          <fkdevicepool>cb49be07-fbb4-0356-33b0-a95bc904b725</fkdevicepool>
          <fkphonetemplate>8e1a10fa-a52c-4435-a4ec-540d266c8c37</fkphonetemplate>
          <fkcallingsearchspace>7c432750-8568-45cc-2dd7-cd8b12fd39e4</fkcallingsearchspace>
          <ctiid>95</ctiid>
          <tkclass>253</tkclass>
          <fkprocessnode/>
          <defaultdtmfcapability>0</defaultdtmfcapability>
          <fklocation>29c5c1c4-8871-4d1e-8394-0b9181e8c54d</fklocation>
          <tkproduct>390</tkproduct>
          <dialplanwizardgenid/>
          <deviceleveltraceflag>f</deviceleveltraceflag>
          <fkenduser>33d23d46-d287-deeb-0f84-0696fdcd58af</fkenduser>
          <allowhotelingflag>f</allowhotelingflag>
          <tkdeviceprofile>4</tkdeviceprofile>
          <ikdevice_defaultprofile/>
          <fkmediaresourcelist/>
          <userholdmohaudiosourceid/>
          <networkholdmohaudiosourceid/>
          <unit>0</unit>
          <subunit>0</subunit>
          <tkcountry/>
          <tkuserlocale/>
          <tkproduct_base/>
          <fkcallingsearchspace_aar/>
          <fkaarneighborhood/>
          <fksoftkeytemplate/>
          <retryvideocallasaudio>t</retryvideocallasaudio>
          <routelistenabled>f</routelistenabled>
          <fkcallmanagergroup/>
          <tkstatus_mlppindicationstatus>0</tkstatus_mlppindicationstatus>
          <tkpreemption>0</tkpreemption>
          <tkstatus_builtinbridge>1</tkstatus_builtinbridge>
          <mtprequired>f</mtprequired>
          <tkqsig>4</tkqsig>
          <tkpacketcapturemode>0</tkpacketcapturemode>
          <packetcaptureduration>0</packetcaptureduration>
          <authenticationstring/>
          <tkcertificatestatus>1</tkcertificatestatus>
          <upgradefinishtime/>
          <fkmlppdomain/>
          <transmitutf8>f</transmitutf8>
          <ignorepi>f</ignorepi>
          <tknetworklocation>2</tknetworklocation>
          <v150modemrelaycapable>f</v150modemrelaycapable>
          <tkcertificateoperation>1</tkcertificateoperation>
          <fksecurityprofile>c6085e14-a32c-4c5e-a3d1-8daf60d81594</fksecurityprofile>
          <fkdialrules/>
          <fkcallingsearchspace_reroute/>
          <fkcallingsearchspace_refer/>
          <unattended_port>f</unattended_port>
          <tkdtmfsignaling>1</tkdtmfsignaling>
          <requiredtmfreception>f</requiredtmfreception>
          <publickey/>
          <fksipprofile>fcbc7581-4d8d-48f3-917e-00b09fb39213</fksipprofile>
          <rfc2833disabled>f</rfc2833disabled>
          <allowcticontrolflag>t</allowcticontrolflag>
          <datetimeinserted/>
          <sshpassword/>
          <sshuserid/>
          <fkcallingsearchspace_restrict/>
          <fkmatrix_presence>ad243d17-98b4-4118-8feb-5ff2e1b781ac</fkmatrix_presence>
          <fkcommonphoneconfig>ac243d17-98b4-4118-8feb-5ff2e1b781ac</fkcommonphoneconfig>
          <tkkeyauthority>0</tkkeyauthority>
          <tksipcodec_mtppreferredorigcodec>1</tksipcodec_mtppreferredorigcodec>
          <md5hash/>
          <srtpallowed>f</srtpallowed>
          <isstandard>f</isstandard>
          <resettoggle>f</resettoggle>
          <tkreset>2</tkreset>
          <versionstamp>0000000000-c7a6c673-7479-46b0-839e-014d3d093963</versionstamp>
          <fkcommondeviceconfig>07f0783d-0b53-896b-d9a5-fbfbc4476970</fkcommondeviceconfig>
          <huntlistforvm>f</huntlistforvm>
          <remotedevice>f</remotedevice>
          <tkstatus_devicemobilitymode>2</tkstatus_devicemobilitymode>
          <dndtimeout>0</dndtimeout>
          <tkdndoption>0</tkdndoption>
          <tkringsetting_dnd/>
          <isdualmode>f</isdualmode>
          <fkcallingsearchspace_cgpntransform/>
          <fkenduser_mobility/>
          <tkoutboundcallrollover>0</tkoutboundcallrollover>
          <tkphonepersonalization>3</tkphonepersonalization>
          <tkstatus_joinacrosslines>0</tkstatus_joinacrosslines>
          <tkbarge>0</tkbarge>
          <tkstatus_usetrustedrelaypoint>2</tkstatus_usetrustedrelaypoint>
          <istrustedrelaypoint>f</istrustedrelaypoint>
          <srtpfallbackallowed>f</srtpfallbackallowed>
          <ispaienabled>t</ispaienabled>
          <isrpidenabled>t</isrpidenabled>
          <tksipprivacy>0</tksipprivacy>
          <tksipassertedtype>0</tksipassertedtype>
          <fkcallingsearchspace_cdpntransform/>
          <usedevicepoolcdpntransformcss>t</usedevicepoolcdpntransformcss>
          <nationalprefix>Default</nationalprefix>
          <internationalprefix>Default</internationalprefix>
          <unknownprefix>Default</unknownprefix>
          <subscriberprefix>Default</subscriberprefix>
          <usedevicepoolcgpntransformcss>t</usedevicepoolcgpntransformcss>
          <ikdevice_primaryphone/>
          <tkstatus_audiblealertingidle>2</tkstatus_audiblealertingidle>
          <tkstatus_audiblealertingbusy>2</tkstatus_audiblealertingbusy>
          <isactive>t</isactive>
          <tkphoneservicedisplay>3</tkphoneservicedisplay>
          <isprotected>f</isprotected>
          <fkmobilesmartclientprofile/>
          <tkstatus_alwaysuseprimeline>2</tkstatus_alwaysuseprimeline>
          <tkstatus_alwaysuseprimelineforvm>2</tkstatus_alwaysuseprimelineforvm>
          <callednationalprefix>Default</callednationalprefix>
          <calledinternationalprefix>Default</calledinternationalprefix>
          <calledunknownprefix>Default</calledunknownprefix>
          <calledsubscriberprefix>Default</calledsubscriberprefix>
          <callednationalstripdigits/>
          <calledinternationalstripdigits/>
          <calledunknownstripdigits/>
          <calledsubscriberstripdigits/>
          <fkcallingsearchspace_callednational/>
          <fkcallingsearchspace_calledintl/>
          <fkcallingsearchspace_calledunknown/>
          <fkcallingsearchspace_calledsubscriber/>
          <hotlinedevice>f</hotlinedevice>
          <fkgeolocation/>
          <fkgeolocationfilter_lp/>
          <sendgeolocation>f</sendgeolocation>
          <nationalstripdigits/>
          <internationalstripdigits/>
          <unknownstripdigits/>
          <subscriberstripdigits/>
          <fkcallingsearchspace_cgpnnational/>
          <fkcallingsearchspace_cgpnintl/>
          <fkcallingsearchspace_cgpnunknown/>
          <fkcallingsearchspace_cgpnsubscriber/>
          <usedevicepoolcalledcssnatl>t</usedevicepoolcalledcssnatl>
          <usedevicepoolcalledcssintl>t</usedevicepoolcalledcssintl>
          <usedevicepoolcalledcssunkn>t</usedevicepoolcalledcssunkn>
          <usedevicepoolcalledcsssubs>t</usedevicepoolcalledcsssubs>
          <pstnaccess>f</pstnaccess>
          <fkvipre164transformation/>
          <usedevicepoolcgpntransformcssnatl>t</usedevicepoolcgpntransformcssnatl>
          <usedevicepoolcgpntransformcssintl>t</usedevicepoolcgpntransformcssintl>
          <usedevicepoolcgpntransformcssunkn>t</usedevicepoolcgpntransformcssunkn>
          <usedevicepoolcgpntransformcsssubs>t</usedevicepoolcgpntransformcsssubs>
          <fkfeaturecontrolpolicy/>
          <runonallnodes>f</runonallnodes>
          <enableixchannel>f</enableixchannel>
          <tkdevicetrustmode>0</tkdevicetrustmode>
          <usedevicepoolrdntransformcss>t</usedevicepoolrdntransformcss>
          <fkcallingsearchspace_rdntransform/>
          <enablebfcp>f</enablebfcp>
          <requirecerlocation>f</requirecerlocation>
          <usedevicepoolcgpningressdn>t</usedevicepoolcgpningressdn>
          <fkcallingsearchspace_cgpningressdn/>
          <earlyoffersupportforvoicecall>f</earlyoffersupportforvoicecall>
          <enablegatewayrecordingqsig>f</enablegatewayrecordingqsig>
          <calreference>-1</calreference>
          <tkcalmode/>
          <ndescription>Agent Softphone for Department Agent Name</ndescription>
          <msisdn/>
          <fkwirelesslanprofilegroup/>
          <enablecallroutingtordwhennoneisactive>f</enablecallroutingtordwhennoneisactive>
          <fkwifihotspotprofile/>
          <allowcfbcontrolofcallsecurityicon>f</allowcfbcontrolofcallsecurityicon>
          <fkelingroup/>
          <ecpublickeycurve/>
          <lscvaliduntil>0</lscvaliduntil>
          <lscissuername/>
          <lscissuervaliduntil>0</lscissuervaliduntil>
          <tktrustreceivedidentity>0</tktrustreceivedidentity>
          <enableactivationid>f</enableactivationid>
          <fkmraservicedomain/>
          <allowmramode>f</allowmramode>
          <isdevicemigrated>f</isdevicemigrated>
        </row>
      </return>
    </ns:executeSQLQueryResponse>
  </soapenv:Body>
</soapenv:Envelope>

Any Help would be greatly appreciated.

 

 

1 Accepted Solution

Accepted Solutions

dstaudt
Cisco Employee
Cisco Employee

This sample shows using <executeSQLQuery> with Zeep: https://github.com/CiscoDevNet/axl-python-zeep-samples/blob/master/axl_executeSQLQuery.py

 

It looks like your object parsing is a bit off here:

print(template_query_resp['row']['return']['pkid'])

where the order should be:

['return']['row']

However, 'row' is going to be a Python list (not a single row) of eTree elements, so you will want to iterate over the list to print your data row-by-row:

for single_row in template_query_resp['return']['row']:
    print(single_row)

BUT: note that since this is an adhoc query, Zeep cannot create a fully formed Python object out of the response, since the AXL schema can't know what columns you've asked for in the SQL.  As a result, a single_row is not a dictionary with a key named 'pkid', but rather a Python list of element objects, so you'll need to access columns by index and get the 'text' value.  'pkid' is the zero-th column in the row, so:

for single_row in template_query_resp['return']['row']:
    print(single_row[0].text)

This is a bit easier if you restrict the number of returned fields to the minimum needed.
If you don't like extracting 'blind' by index, you can make a small function to look up the value by tag:

def get_column(tag, row):
    element = list(filter(lambda x: x.tag == tag, row))
    return element[0].text if len(element) > 0 else None
for single_row in template_query_resp['return']['row']:
print(get_column('pkid', single_row))

 

View solution in original post

4 Replies 4

npetrele
Cisco Employee
Cisco Employee

Is it possible that you need to parse the XML that is returned?  Here's a page from Python docs that deal with this:

 

https://docs.python.org/3/library/xml.etree.elementtree.html

 

npetrele
Cisco Employee
Cisco Employee

Now that I look at it again, I think what you're getting back are elements of variables by memory address:

 

<Element enablebfcp at 0x1b2ac5a0600>

So that's enablefcp, which is stored at memory address 0x1b2ac5a0600.

 

I dealt with this issue a year or two ago, and I'm digging through my archives to see how I solved it. I'll come back and post if I can find the answer.

dstaudt
Cisco Employee
Cisco Employee

This sample shows using <executeSQLQuery> with Zeep: https://github.com/CiscoDevNet/axl-python-zeep-samples/blob/master/axl_executeSQLQuery.py

 

It looks like your object parsing is a bit off here:

print(template_query_resp['row']['return']['pkid'])

where the order should be:

['return']['row']

However, 'row' is going to be a Python list (not a single row) of eTree elements, so you will want to iterate over the list to print your data row-by-row:

for single_row in template_query_resp['return']['row']:
    print(single_row)

BUT: note that since this is an adhoc query, Zeep cannot create a fully formed Python object out of the response, since the AXL schema can't know what columns you've asked for in the SQL.  As a result, a single_row is not a dictionary with a key named 'pkid', but rather a Python list of element objects, so you'll need to access columns by index and get the 'text' value.  'pkid' is the zero-th column in the row, so:

for single_row in template_query_resp['return']['row']:
    print(single_row[0].text)

This is a bit easier if you restrict the number of returned fields to the minimum needed.
If you don't like extracting 'blind' by index, you can make a small function to look up the value by tag:

def get_column(tag, row):
    element = list(filter(lambda x: x.tag == tag, row))
    return element[0].text if len(element) > 0 else None
for single_row in template_query_resp['return']['row']:
print(get_column('pkid', single_row))

 

Thank you!

 

This worked perfectly