0

I have an app that connects to account storage files in azure. I am using Python to connect account storage resource. One of the functions I use is 'create_directory()' from class 'from azure.storage.fileshare import (ShareDirectoryClient)'. Occasionally, Appears log:

Azure.core.exceptions.ServiceRequestError: (<urllib3.connection.HTTPSConnection object at 'object_resurce', 'Connection to 'name_of_the_account_storage_resurce'.file.core.windows.net timed out. (connect timeout=20)')

the func:

def create_dir(self,dir_name:str):
        """ 
        This function will create a new directory in the storage account
        Args:
        -----
            share_name (str): The share client name of storage account.
            dir_name (str): The name of the created directory .
        """
        
      
            #check if the directory is exists in account storage
            if(self.dir_exists(dir_name)==False):
                # Create a DirectoryClient from a connection string
                self.dir_client = 
            ShareDirectoryClient.from_connection_string(                         
            conn_str=self.connection_string,
                                        share_name=self.share, 
                                        directory_path=dir_name)
            
                self.dir_client.create_directory(timeout=60)

How can I fix it?

Tried to add timeout between connection tries, but didn't fix it

1 Answers1

0

I tried in my environment and successfully created directory in the azure file share.

Code:

from  azure.storage.fileshare  import  ShareDirectoryClient
connection_string="< Connection string >"
share_name="fileshare1"
dir_name="directory1"
dir_client = ShareDirectoryClient.from_connection_string(connection_string, share_name, dir_name)
print("Creating directory:", share_name + "/" + dir_name)
dir_client.create_directory()
print("Directory created!!!")

Console:

enter image description here

Portal:

enter image description here

Reference: Develop for Azure Files with Python | Microsoft Learn

Venkatesan
  • 3,748
  • 1
  • 3
  • 15