Search code examples
azureazure-sdkazure-sdk-python

module 'azure.common.credentials' has no attribute 'signed_session'


I need help understanding the exception I'm getting from Azure SDK for Python.

So I'm trying to use the following code to get a list of public IPs from Azure:

import azure.common.credentials as creds
from azure.mgmt.subscription import SubscriptionClient
from azure.mgmt.network.v2019_02_01 import NetworkManagementClient

credentials = creds.get_azure_cli_credentials(resource=None, with_tenant=False)[0]
sub_client = SubscriptionClient(credentials)
subs = [sub.as_dict() for sub in sub_client.subscriptions.list()]

for s in subs:
  sub_id = s['id'][15:]
  network_client = NetworkManagementClient(creds, sub_id)
  pub_ips = network_client.public_ip_addresses.list_all()
  print("done")
  for ip in pub_ips:
    print(ip.ip_address)

Here is the output:

Traceback (most recent call last):
done
  File "/Users/user/repo/azure_public_ip.py", line 18, in <module>
    for ip in pub_ips:
  File "/usr/local/lib/python3.7/site-packages/msrest/paging.py", line 143, in __next__
    self.advance_page()
  File "/usr/local/lib/python3.7/site-packages/msrest/paging.py", line 129, in advance_page
    self._response = self._get_next(self.next_link)
  File "/usr/local/lib/python3.7/site-packages/azure/mgmt/network/v2019_02_01/operations/public_ip_addresses_operations.py", line 445, in internal_paging
    response = self._client.send(request, stream=False, **operation_config)
  File "/usr/local/lib/python3.7/site-packages/msrest/service_client.py", line 336, in send
    pipeline_response = self.config.pipeline.run(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/msrest/pipeline/__init__.py", line 197, in run
    return first_node.send(pipeline_request, **kwargs)  # type: ignore
  File "/usr/local/lib/python3.7/site-packages/msrest/pipeline/__init__.py", line 150, in send
    response = self.next.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/msrest/pipeline/requests.py", line 65, in send
    self._creds.signed_session(session)
AttributeError: module 'azure.common.credentials' has no attribute 'signed_session'

As you can see, the "done" message prints, so the exception doesn't happen until I try to iterate through the list of public IPs. I'm confused by this error, because it makes it sound like there's something wrong with the credentials. But how can this be the case if the request for the list of public IPs doesn't cause an exception? If I remove the last two lines, there is no exception.


Solution

  • This line:

    network_client = NetworkManagementClient(creds, sub_id)
    

    should be

    network_client = NetworkManagementClient(credentials, sub_id)
    

    Right now you are passing the module you imported at line 1