1

I want to read some csv files, which are stored in a zip file, which is protected by a password. So the structure is: 1.zip: (a.csv, aa.csv, 12.csv ...)

and the password is: 'pass'.

I am try to following this question: Python - the zipfile module doesn't seem to work with passwords

and have a code with this question: Read multiple csv files zipped in one file

for zip_file in glob.glob("C:/.../1.zip"):
    zf = zipfile.ZipFile(zip_file)
    pw = 'pass'
    zf.setpassword(pw)
    dfs = [pd.read_csv(zf.open(f), sep="\t") for f in zf.namelist()]
    df = pd.concat(dfs,ignore_index=True)

I get the error:

TypeError: pwd: expected bytes, got str

What is the mistake?

PV8
  • 5,799
  • 7
  • 43
  • 87

0 Answers0