Reputation: 65
I am getting an exception which am transferring to a variable. The output of the variable is given below:
schema.SchemaError("Key 'policy' error:\nOr({'name': And(<class 'str'>, <built-in function len>), 'age': And(<class 'int'>, <function <lambda> at 0x000001C964E92DC8>), Optional('gender'): And(<class 'str'>, Use(<method 'lower' of 'str' objects>), <function <lambda> at 0x000001C964E92E58>)}) did not validate {'name': 'Sue', 'age': 28, 'gnder': 'Squid'}\nWrong key 'gnder' in {'name': 'Sue', 'age': 28, 'gnder': 'Squid'}")
Please let me know how I can get the contents of this variable, I could try to convert this into a string but then it becomes very cumbersome to extract the contents. I specifically want the contents after 'did not validate' part.
EDIT - Not looking to resolve the error, error was expected. I transferred the contents of the exception to a variable, just need to figure out how to read the variable.
Upvotes: 0
Views: 4825
Reputation: 351
variable
string
did not validate
in the converted string127
th position{
in the string as it is the starting after the errorposition
a
for confirmationa = schema.SchemaError("Key 'policy' error:\nOr({'name': And(<class 'str'>, <built-in function len>), 'age': And(<class 'int'>, <function <lambda> at 0x000001C964E92DC8>), Optional('gender'): And(<class 'str'>, Use(<method 'lower' of 'str' objects>), <function <lambda> at 0x000001C964E92E58>)}) did not validate {'name': 'Sue', 'age': 28, 'gnder': 'Squid'}\nWrong key 'gnder' in {'name': 'Sue', 'age': 28, 'gnder': 'Squid'}")
a = str(a)
b = 127 #every error starts from here
a = a[b:len(a)]
c = a.find("{")
a = a[c:len(a)]
print(a)
Upvotes: 2