admin管理员组

文章数量:1122832

Below is the code.

from zipfile import ZipFile 

file_name = "XYZ.zip"

with ZipFile(file_name, 'r') as zip: 
    zip.printdir()
    print('Extracting all the files now...') 
    zip.extractall(pwd=b'123123$SADMK6%002#')
    print('Done!')

It is giving "FileNotFoundError" error. Also, I can read other csv files inside ADLS using abfss path without providing accesskey of storage account.

Below is the code.

from zipfile import ZipFile 

file_name = "XYZ.zip"

with ZipFile(file_name, 'r') as zip: 
    zip.printdir()
    print('Extracting all the files now...') 
    zip.extractall(pwd=b'123123$SADMK6%002#')
    print('Done!')

It is giving "FileNotFoundError" error. Also, I can read other csv files inside ADLS using abfss path without providing accesskey of storage account.

Share Improve this question asked Nov 21, 2024 at 8:51 Govind GuptaGovind Gupta 1,6954 gold badges16 silver badges24 bronze badges 5
  • How you are reading other files? using open or pandas read csv? – JayashankarGS Commented Nov 21, 2024 at 8:54
  • are you using databricks? – JayashankarGS Commented Nov 21, 2024 at 9:35
  • I am using synapse notebook. @jaya – Govind Gupta Commented Nov 22, 2024 at 4:32
  • provide pwd field while doing extractall – JayashankarGS Commented Nov 22, 2024 at 4:46
  • Is below solution helpfull? @Govind Gupta – JayashankarGS Commented Nov 25, 2024 at 4:25
Add a comment  | 

1 Answer 1

Reset to default 0

csv files are read using abfss path because you are using pandas to read them and pandas uses fsspec and adlfs library which connects to azure storage account using credentials you given.

You did not provided any access key it still worked because it used you default credentials, and with the same you can read zip file like below.

from fsspec.implementations.zip import  ZipFileSystem

strg_opt={'account_name': "jadls", 'anon': False}
tmp = ZipFileSystem(fo="abfs://data/zips/apache-maven-3.9.9-bin.zip",target_options=strg_opt)
tmp.zip.extractall(path="./maven")

Here, the path format should be

'abfs://{CONTAINER}/{FOLDER}/file_name'

refer this for more information.

Output:

In storage account

and extracted in local

If you are using Databricks environment, then mount your storage account using dbutils.fs.mount() and use your initial code on that mount path.

本文标签: azureHow do I unzip a password protected zip file using Python inside ADLSStack Overflow