The sovereign cloud examples (here: https://docs.microsoft.com/en-us/azure/developer/python/azure-sdk-sovereign-domain?view=azure-python) are not functional with the current versions of the azure libraries.
The examples given all fail with a missing get_token attribute:
AttributeError: 'UserPassCredentials' object has no attribute 'get_token'
https://github.com/Azure/azure-sdk-for-python/issues/12947 pointed out the existence of the credential_scopes argument, which led to a functional script using azure.identity.DefaultAzureCredential:
from azure.mgmt.resource import SubscriptionClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
subscription_client = SubscriptionClient(credential, base_url='https://management.usgovcloudapi.net/', credential_scopes=['https://management.usgovcloudapi.net/.default'])
subscription = next(subscription_client.subscriptions.list())
print(subscription.subscription_id)
The credential_scopes argument doesn't appear to be in the docs anywhere, but seems to be required.
Packages in the venv I tested with:
Package Version
------------------------ ---------
adal 1.2.5
azure-common 1.1.26
azure-core 1.9.0
azure-identity 1.5.0
azure-mgmt-authorization 0.61.0
azure-mgmt-core 1.2.2
azure-mgmt-nspkg 3.0.2
azure-mgmt-resource 15.0.0
azure-nspkg 3.0.2
certifi 2020.11.8
cffi 1.14.3
chardet 3.0.4
cryptography 3.2.1
enum34 1.1.10
idna 2.10
ipaddress 1.0.23
isodate 0.6.0
msal 1.6.0
msal-extensions 0.3.0
msrest 0.6.19
msrestazure 0.6.4
oauthlib 3.1.0
pathlib2 2.3.5
pip 20.2.4
portalocker 1.7.1
pycparser 2.20
PyJWT 1.7.1
python-dateutil 2.8.1
requests 2.25.0
requests-oauthlib 1.3.0
scandir 1.10.0
setuptools 44.1.1
six 1.15.0
typing 3.7.4.3
urllib3 1.26.2
wheel 0.35.1
Hi @dmurnane, you're correct about both the problem and the solution. That document needs to be updated because it assumes a version of azure-mgmt-resource (<= 10.x) that expects a credential type from msrestazure, whereas the newest version (15.x) expects a credential type from azure-identity.
@jongio @kraigb, is this sovereign cloud documentation tracked for an update?
Yes, I'm in the process of making updates for newer management libraries. Thanks.
Sorry for the late reply, but I updated the article a week or so ago and it's now current.