Skip to content

TypeError: argument of type 'NoneType' is not iterable in msal_client.py #23483

@micafer

Description

@micafer
  • Azure.Identity:
  • 1.8.0:
  • Ubuntu 20.04:
  • Python 3.8:

Describe the bug

Sometimes when authenticating with ClientSecretCredential class I get this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/azure/identity/_internal/decorators.py", line 56, in wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/azure/identity/_credentials/user_password.py", line 58, in _request_token
    return app.acquire_token_by_username_password(
  File "/usr/local/lib/python3.8/dist-packages/msal/application.py", line 1417, in acquire_token_by_username_password
    user_realm_result = self.authority.user_realm_discovery(
  File "/usr/local/lib/python3.8/dist-packages/msal/authority.py", line 128, in user_realm_discovery
    resp.raise_for_status()
  File "/usr/local/lib/python3.8/dist-packages/azure/identity/_internal/msal_client.py", line 55, in raise_for_status
    if "error" in content or "error_description" in content:
TypeError: argument of type 'NoneType' is not iterable

To Reproduce
Steps to reproduce the behavior:
The error appears sometimes, I cannot reproduce the error with a fixed set ot steps.

Expected behavior

It should raise a ClientAuthenticationError with the correct error.

Additional context

I suggest to change this line:
https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/azure/identity/_internal/msal_client.py#L53

from:

if ContentDecodePolicy.CONTEXT_NAME in self._response.context:

to:

if ContentDecodePolicy.CONTEXT_NAME in self._response.context and self._response.context[ContentDecodePolicy.CONTEXT_NAME]:

Metadata

Metadata

Assignees

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions