02-04-2021 01:05 PM
Hello,
I am trying to run the following python program to obtain product information from CUCM.
The python program errors out with the following message -
Zeep error: getProductInformationList: Unknown fault occured
However while using postman I can retrieve data.
Python code below -
from lxml import etree import requests from requests import Session from requests.auth import HTTPBasicAuth from zeep import Client, Settings, Plugin from zeep.transports import Transport from zeep.exceptions import Fault import os import sys from dotenv import load_dotenv load_dotenv() DEBUG = os.getenv( 'DEBUG' ) == 'True' WSDL_FILE = 'file://C:/Users/serviceability-python-zeep-samples/schema/ControlCenterServices.wsdl' class MyLoggingPlugin( Plugin ): def egress( self, envelope, http_headers, operation, binding_options ): if not DEBUG: return 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 ): if not DEBUG: return 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 = False requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning) username = 'admin' password = 'password' host = '1.1.1.1' session.auth = HTTPBasicAuth( os.getenv( username ), os.getenv( password ) ) 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://schemas.cisco.com/ast/soap}ControlCenterServicesBinding', f'https://{host}:8443/controlcenterservice2/services/ControlCenterServices' ) try: resp = service.getProductInformationList(ServiceInfo='') except Fault as err: print( f'Zeep error: getProductInformationList: {err}' ) sys.exit( 1 ) print( "\ngetProductInformationList response:\n" )
Solved! Go to Solution.
02-04-2021 01:22 PM
After spending another hour on this code figured out a syntactical error.
02-04-2021 01:22 PM
After spending another hour on this code figured out a syntactical error.
10-22-2021 07:24 AM
what was the mistake?
10-25-2021 12:05 AM
Hi!
Do you working with environment variable or do you want to use credentials from the code?
Your code want to use username and password from your
environment variable (os.getenv( username ) , os.getenv( password) ) to create a session authentication.
If you want to use environment variable:
- create in your python code directory a file .env like this
username = 'admin'
password = 'password'
host = '1.1.1.1'
DEBUG=True
- change following line in your code
service = client.create_service(
'{http://schemas.cisco.com/ast/soap}ControlCenterServicesBinding',
'https://{}:8443/controlcenterservice2/services/ControlCenterServices'.format(os.getenv('host'))
)
CHECK YOUR ENVIRONMENT VARIABLES
- Existing entries in your ENVIRONMENT VARIABLES are not overwritten (like USERNAME).
To check this use a simple print(os.environ) or print(os.getenv( 'username' )).
To be able to overwrite them change yout to to:
load_dotnev(override=True)
If you want to use credentials from your python code:
username = 'admin'
password = 'password'
host = '1.1.1.1'
session.auth = HTTPBasicAuth( username, password )
Here is another helful link (many thanks to dstaudt):
https://github.com/CiscoDevNet/serviceability-python-zeep-samples
If you have any questions, please get in touch
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide