The failure shouldn't be "KeyError: 'domain'" -- since tokens might not have a domain, the code should check if 'domain' isn't in the dict and fail with a more appropriate error message... could just be change to .get('domain') rather than ['domain']
The failure shouldn't be "KeyError: 'domain'" -- since tokens might not have a domain, the code should check if 'domain' isn't in the dict and fail with a more appropriate error message... could just be change to .get('domain') rather than ['domain']