Getting "TypeError: pwd: expected bytes, got str" when extracting zip file with password

Viewed 6373

I want to unzip a specific named file located in a specific directory.

The name of the file = happy.zip.
The location = C:/Users/desktop/Downloads.

I want to extract all the files to C:/Users/desktop/Downloads(the same location)

I tried:

import zipfile
import os
in_Zip = r"C:/Users/desktop/Downloads/happy.zip"
outDir = r"C:/Users/desktop/Downloads"
z = zipfile.ZipFile(in_Zip, 'r')
z.extractall(outDir, pwd='1234!')
z.close

But I got:

"TypeError: pwd: expected bytes, got str"

2 Answers

Please note that this will only work if the zip file has been encrypted using the "Zip legacy encryption" option when setting up the password.

Related