Python 解压还密码的压缩文件 LookupError: Couldn't find path to unrar library.
Python 解压还密码的压缩文件(rar zip)

安装包
pip install unrar -i https://pypi.tuna.tsinghua.edu.cn/simple
from unrar import rarfile
from tqdm import tqdm
import itertools
def rar_attack(file_name):
    file_handle = rarfile.RarFile(file_name)
    for length in range(1, 9):
        # 思路是这样,但实际运行过程中,会消耗大量资源,耗时较长
        # for combination in tqdm(itertools.product('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()', repeat=length)):
        for combination in tqdm(itertools.product('0123456789', repeat=length)):
            password = ''.join(combination)
            try:
                file_handle.extractall(pwd=password)
                print('Password found: ', password)
                return
            except:
                pass
if __name__ == '__main__':
    # 压缩包,需要和代码同级
    file_name = '123.rar'
    rar_attack(file_name)


问题
如果报LookupError: Couldn't find path to unrar library.
解决方案如下:
- 官网下载
 RARLab官方下载库文件 下载地址: https://www.rarlab.com/rar/unrardll-624.exe
- 安装路径
 执行 UnRARDLL.exe 文件 ,路径选择默认 ,一般是C:\Program Files (x86)\UnrarDLL\ 目录下


unrar.rarfile.BadRarFile: Invalid RAR file.
解决方案:
- 下载 UnRAR.exe https://www.rarlab.com/rar/unrarw64.exe
 将 UnRAR.exe 复制到代码同级目录下,或者添加环境变量
  
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/17987727
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号