Skip to content

Commit 403a3e8

Browse files
committed
Catch operations on None object if content could not be found in an XML tree
1 parent adc6323 commit 403a3e8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

office365/runtime/auth/saml_token_provider.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,21 @@ def process_service_token_response(self, response):
115115
if xml.find('{0}Body/{0}Fault'.format(ns_prefixes['S'])) is not None:
116116
error = xml.find('{0}Body/{0}Fault/{0}Detail/{1}error/{1}internalerror/{1}text'.format(ns_prefixes['S'],
117117
ns_prefixes['psf']))
118-
self.error = 'An error occurred while retrieving token: {0}'.format(error.text)
118+
if error is None:
119+
self.error = 'An error occurred while retrieving token from XML response.'
120+
else:
121+
self.error = 'An error occurred while retrieving token from XML response: {0}'.format(error.text)
119122
logger.error(self.error)
120123
return None
121124

122125
# extract token
123126
token = xml.find(
124127
'{0}Body/{1}RequestSecurityTokenResponse/{1}RequestedSecurityToken/{2}BinarySecurityToken'.format(
125128
ns_prefixes['S'], ns_prefixes['wst'], ns_prefixes['wsse']))
129+
if token is None:
130+
self.error = 'The service token could not be extracted from the XML response.'
131+
logger.error(self.error)
132+
return None
126133
logger.debug_secrets("token: %s", token)
127134
return token.text
128135

0 commit comments

Comments
 (0)