Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
zipfile
#1
i am getting error "expected bytes, got str"

here is the python code:
----------------------
import zipfile
zFile = zipfile.ZipFile("evil.zip")
passFile = open('dictionary.txt')
for line in passFile.readlines():
    password = line.strip('\n')
    try:
        zFile.extractall(pwd=password)
        print('[+] Password = ' + password + '\n')
        exit(0)
    except Exception as e:
        print(e)
------------------------
Reply
#2
It looks like the password parameter needs to be bytes rather than a string. Try instead:

        zFile.extractall(pwd=password.encode("utf-8"))
Or... if the password dictionary is already bytes instead of utf-8 characters, open it that way instead of as text.

passFile = open('dictionary.txt', 'rb') # open as bytes
for line in passFile.readlines():
    password = line.rstrip()            # password is bytes
[...]
    print(f"[+] Password = {password}") # don't concat bytes&string, but can convert for printing
[...]
Reply
#3
thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using zipfile module - finding folders not files darter1010 2 268 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  zipfile module error pseudo 3 770 Jun-30-2023, 03:52 PM
Last Post: Gribouillis
  [Solved by deanhystad] Create a zip file using zipfile library DZ_Galaxy 2 1,162 Aug-17-2022, 04:57 PM
Last Post: DZ_Galaxy
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 1,628 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  Created zipfile without all the subfolder? korenron 3 3,768 Jun-23-2021, 12:44 PM
Last Post: korenron
  Create ZIP file not working using ZipFile? korenron 1 2,112 Jun-13-2021, 04:15 PM
Last Post: korenron
  zip file variable prints <zipfile.ZipFile object at 0x7f83fd13bd90> ? Rsh 9 4,148 Jun-27-2019, 02:00 PM
Last Post: Rsh
  python zipfile.ZipFile makes zip file but can't add folders to them CashMunny 3 3,634 May-09-2018, 10:28 PM
Last Post: CashMunny

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020