Python 3 for scripting in Microfocus Network Automation.

  • KM03091102
  • 08-Feb-2018
  • 12-May-2021


The purpose of this document is to expose how explain how to integrate Python 3 with Microfocus Network Automation as well as some of the advantages.


Introduction – Why Python 3


Python is one of the most popular scripting languages used nowadays (Lutz, 2013):

·         Software quality: Python code was designed readable hence reusable and maintainable.

·         Developer productivity: compared to the compiled languages, Python is easier to debug and maintain.

·         Program portability: Python is available in the major computer platforms.

·         Support libraries: it comes with a large collection of prebuilt libraries (standard libraries). Around internet there is a vast collection of third party libraries.

·         Component integration: python supports a variety of integration mechanism. So that it can work with native libraries, Java, .NET and other frameworks; thanks to protocols like SOAP, XML-RPC and CORBA, it can interact with Web applications.

·         Enjoyment: there is an intangible advantage when it is easy to get the things done.

The more popular uses for Python are: system programming, GUIs, Internet scripting, component integration, rapid prototyping, numeric and scientific programming, games, data mining, etc…

Python 3 includes a lot of improvements in the language which break the compatibility with Python 2, between the new features includes (ActiveState, 2017):

·         The integer division which is much simpler and stronger in Python 3.

·         Asynchronous support.

·         Better exception handling.

·         Unicode support.

·         Python 3 can mix tabs and spaces.

·         Function annotations.

·         Memory objects which are significantly more memory efficient.


How to create Python3 scripts for Microfocus Network Automation



·         Python 3 (examples shown in this document were tested with miniconda).

·         The library for SOAP communications called “suds-jurko”.

·         The binding.




It’s an easy to install Python environment available for Windows, MacOS and Linux (

It installs a Python instance independently to the one installed in the system. 

Installation steps:

·         Install Miniconda3

·         Install Suds by Jurkos:

                ./conda install suds-jurko

·         Copy the binding in a convenient location.



Disclaimer this example is used to illustrate the workaround it was provided with no warranties.


1.       List devices in the inventory:

deviceGroup = "Inventory"


from SOAPbinding import NetworkAutomationSOAPConnection


soappyFile = 'SOAPbinding/hpna10_30_api.wsdl.soappy'

myserver, myuser, mypassword = '', 'myuser', 'mypassword'

na = NetworkAutomationSOAPConnection(myserver, myuser, mypassword, soappyFile)


ld_result = na.execute('list_device', {'group':deviceGroup})




   Status = "501"

   ResultSet =


         Row[] =


               accessMethods = "TFTP:SFTP:FTP:HTTPS:HTTP:SCP:SNMP:CLI+commstr:ssh:telnet"

               assetTag = None

               changeEventData = "<event>201,command script execution,2018:01:05:11:14:45,"",null</event>

<event>201,command script execution,2018:01:05:11:39:04,"",null</event>


               comments = None

               createDate = "Fri Jan 05 11:11:59 CST 2018"

               deviceGroup1ID = 12

               deviceID = 201

               deviceName = None

               driverName = "Avocent"

               excludeFromPoll = 0

               feedSource = "Manually added by User-1deviceAtTime"

               forceSave = "false"

               geographicalLocation = None

               hostName = ""

               lastAccessAttemptDate = "Tue Feb 06 09:53:33 CST 2018"

               lastAccessAttemptStatus = "Take Snapshot: Problem accessing device"

               lastModifiedUserID = 1

               lastRecordModifiedDate = "Tue Feb 06 09:53:34 CST 2018"

               lastSnapshotAttemptDate = "Tue Feb 06 09:53:33 CST 2018"

               lastSnapshotAttemptStatus = "Problem accessing device"

               managementStatus = 0

               model = None

               performACLParsing = 2

               primaryFQDN = None

               primaryIPAddress = ""

               serialNumber = None

               siteID = 1

               siteName = "Default Site"

               vendor = None






Some examples can be downloaded HERE. The pack also includes the binding and several api.wsdl.soappy files.

                Example script


How to use Python 3 for advanced scripting:


1.       Set Python 3 like interpreter in: 

General menu --> Admin > Administrative settings > Server

Advanced Scripting

2.       Create advanced scripts that starts with:



SOAPPYFILE     = "HERE_THE_NA_PATH/client/sdk/api.wsdl.soappy"


import sys

sys.path.insert(0, BINDING_PATH)

from SOAPbinding import NetworkAutomationSOAPConnection

from credentials import *

na = NetworkAutomationSOAPConnection("http://localhost", "$tc_user_username$", "$tc_user_password$", SOAPPYFILE)



For example:


            Interpreter configuration:

            Interepreter configuration




BINDING_PATH      = "/opt/Python/API_Python/"

SOAPPYFILE  = "/opt/NA/client/sdk/api.wsdl.soappy"


import sys

sys.path.insert(0, BINDING_PATH)

from SOAPbinding import NetworkAutomationSOAPConnection

from credentials import *

na = NetworkAutomationSOAPConnection("http://localhost", "$tc_user_username$", "$tc_user_password$", SOAPPYFILE)


results = na.execute('show_latest_access', {'ip': '$tc_device_ip$'})









Known problems:


Problem: SUDS creates many temporal files.



Problem: Complex type not found. The scripts dies and left this error message:

    raise TypeNotFound(content.node.qname())

suds.TypeNotFound: Type not found: 'nas:_newDeviceInImport'


Go to <NA_HOME>/jre/appserver.rcx  (first backup):

Locate the block: <array name="api/soap_filter_columns/10/g">

Rename it to: <array name="api/soap_filter_columns/10/10">

Make sure that this line is not present: <value>_newDeviceInImport</value>

Make sure that this line is present: <value>__newDeviceInImport</value>


Reload the server.

HP Network Automation Version 10.11.05


Type "HELP connect" to see how to connect to a device.

Type "HELP" to view a list of available commands.



NA>reload server options

200 OK: Generic Succeeded

Removed: api/soap_filter_columns/10/g=[__m_extraObjects, __loadedSecondaryIPs, __columnUpdateMap, __columnUpdateSet, __newDeviceInImport, __changedInCache, localizedComments, localizedDeviceGroupName, durationStr]

Added: api/soap_filter_columns/10/10=[__m_extraObjects, __loadedSecondaryIPs, __columnUpdateMap, __columnUpdateSet, __newDeviceInImport, __changedInCache, localizedComments, localizedDeviceGroupName, durationStr]







Lutz, M. (2013). Learning Python. Sebastopol, CA: O'Reilly.

ActiveState. (2017). Python 3 vs Python 2: It’s Different This Time. [online] Available at: [Accessed 6 Feb. 2018].



I hope you find this information useful.

Saúl Vega Chacón.


Python 3 for scripting in Microfocus Network Automation