Azure - Storage service - Storage sync service - Module Import error - cannot import name 'StorageSyncManagementClient' from 'azure.mgmt.storagesync

Prabhakaran Haribaskar 0 Reputation points
2023-02-17T13:39:34.2133333+00:00
**Error :** 
I am trying to get data of Storage sync service under storage service and i am getting below error.
Module Import error - cannot import name 'StorageSyncManagementClient' from 'azure.mgmt.storagesync

**Steps i have followed to overcome the error:**
I tried to install the module by using pip install azure.mgmt.storagesync 
Then i upgrade the module to the current version by using pip install --upgrade azure-mgmt-storagesync

**Code i used to get the storage sync service details**
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storagesync import StorageSyncManagementClient
from msrestazure.azure_exceptions import CloudError

credential = DefaultAzureCredential()
subscription_id = 'for privacy i didn't mention
resource_client = ResourceManagementClient(
    credential,
    subscription_id
)
sync_service_client = StorageSyncManagementClient(
    credential,
    subscription_id
)
sync_services = []
for item in resource_client.resources.list(filter="resourceType eq 'Microsoft.StorageSync/storageSyncServices'"):
    try:

        sync_service = sync_service_client.storage_sync_services.get(
            item.id.split('/')[4],  # resource group name
            item.name  # resource name
        )

        sync_services.append({
            'name': sync_service.name,
            'location': sync_service.location,
            'resource_group': item.id.split('/')[4],
            'storage_account': sync_service.storage_account_id
        })

    except CloudError as e:
        print('Could not get details for Storage Sync Service "{}" in resource group "{}". Error: {}'.format(
            item.name, item.id.split('/')[4], e
        ))

for sync_service in sync_services:
    print('Name:', sync_service['name'])
    print('Location:', sync_service['location'])
    print('Resource Group:', sync_service['resource_group'])
    print('Storage Account ID:', sync_service['storage_account'])
    
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,530 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,427 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sumarigo-MSFT 47,466 Reputation points Microsoft Employee Moderator
    2023-02-20T11:29:37.77+00:00

    @Prabhakaran Haribaskar Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    The error message you are encountering suggests that the module 'StorageSyncManagementClient' cannot be imported from the 'azure.mgmt.storagesync' package. This error can occur if the package is not installed or if the package is installed but the module is not available in the version you are using.

    You can try installing the latest version of the 'azure-mgmt-storagesync' package using the following command:

    https://pypi.org/project/azure-mgmt-storagesync/

    pip install azure-mgmt-storagesync
    

    If the issue persists, you can try uninstalling and reinstalling the package using the following command:

    pip uninstall azure-mgmt-storagesync
    pip install azure-mgmt-storagesync
    

    If the issue still persists, you can try checking the documentation for the package to see if there are any known issues or compatibility issues with the version of Python you are using.

    You can also try checking the Azure documentation for more information on the 'StorageSyncManagementClient' module and how to use it.
    Develop for Azure Files with Python

    Please let us know if you have any further queries. I’m happy to assist you further.       


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.