type lookuperror

meInvent bbird jobmattcon at gmail.com
Wed Aug 17 22:13:01 EDT 2016


would like to check errors for every function i run, 
got error type lookuperror

def checkexception(func, **kwargs):
    try:
        result = func(*tuple(value for _, value in kwargs.iteritems()))
    except:
        print "Unexpected error:", sys.exc_info()[0]
        try: 
            print(func.__doc__)
        except:
            print("no doc error")
       

>>> mm =checkexception("".encode,encoding='ascii',errors='ignore')
Unexpected error: <type 'exceptions.LookupError'>
S.encode([encoding[,errors]]) -> object

Encodes S using the codec registered for encoding. encoding defaults
to the default encoding. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that is able to handle UnicodeEncodeErrors.


for p in val_list:
   for k, v in p.items():
       if k == "tenant_id":
           print(v)
           m = v
           ten = checkexception(keystone_client.tenants.get, checkexception(m.encode,encoding='ascii',errors'ignore'))
           print(ten.name)



More information about the Python-list mailing list