title: Azure Function - Unzip password protected file using python code
body: <p>I am trying to unzip password protected file which is stored on Azure Blob container. I want to extract it on Azure Blob itself. I have created a Azure Function App using Python (currently it is Timer Control event based) to test things -</p>
  <p>Following is my code - I am not sure what would be the correct way to achieve this</p>
  <pre><code>import datetime
  import os, uuid
  import azure.functions as func
  import azure.storage.blob
  from zipfile import ZipFile
  from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
  
  def test_func():
      #get connection string to storage account
      connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
  
      # BlobServiceClient object which will be used refer to a container client
      blob_service_client = BlobServiceClient.from_connection_string(connect_str)
  
      # Create a unique name for the container
      container_name = &quot;zipextract&quot;
      container_client =  blob_service_client.get_container_client(container_name)
  
      blob_list = container_client.list_blobs()
  
      for blob in blob_list:
          print(&quot;----&gt; &quot; + blob.name)
          with ZipFile(blob.name) as zf:
              zf.extractall(pwd=b'password')   
  </code></pre>
  <p>Now, when I am trying to access file using ZipFile() function - it says &quot;No such file or directory: 'TestZip.zip' &quot;.</p>
  <p>Following is the error message - (TestZip.zip is the zip file placed on zipextract container)</p>
  <pre><code>Result: Failure Exception: FileNotFoundError: [Errno 2] No such file or 
  directory: 'TestZip.zip' Stack: File &quot;/azure-functions- 
  host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py&quot;, line 
  271, in _handle__function_load_request func = loader.load_function( File 
  &quot;/azure-functions- 
  host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py&quot;, 
  line 32, in call return func(*args, **kwargs) File &quot;/azure-functions- 
  host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py&quot;, line 76, 
  in load_function mod = importlib.import_module(fullmodname) File 
  &quot;/usr/local/lib/python3.8/importlib/__init__.py&quot;, line 127, in import_module 
  return _bootstrap._gcd_import(name[level:], package, level) File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 991, in _find_and_load File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 961, in _find_and_load_unlocked File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 991, in _find_and_load File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked File &quot;&lt;frozen 
  importlib._bootstrap_external&gt;&quot;, line 783, in exec_module File &quot;&lt;frozen 
  importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed File 
  &quot;/home/site/wwwroot/TimerTrigger1/__init__.py&quot;, line 39, in &lt;module&gt; 
  test_func() File &quot;/home/site/wwwroot/TimerTrigger1/__init__.py&quot;, line 33, in 
  test_func with ZipFile(blob.name) as zf: File 
  &quot;/usr/local/lib/python3.8/zipfile.py&quot;, line 1251, in __init__ self.fp = 
  io.open(file, filemode)
  </code></pre>
  <p>Any help as to how would I unzip this file? The unzipping is working fine on local machine, however, not sure how would I make it run so that it refers to blob instead of local file.</p>
  <p>Thank you.</p>