Python中open(image_path, "rb")出现File Not Found Error问题求助
解决LG Gallery Decryptor的File Not Found Error问题
错误原因排查
以下是触发open(image_path, "rb")文件找不到错误的常见原因:
- 相对路径不匹配:执行命令中使用的
encrypted/xxx.dm是相对路径,需确认encrypted文件夹与decryptlg.py脚本在同一目录下。 - 文件名/路径拼写错误:手动输入的文件名可能存在大小写、字符偏差(Linux/macOS系统严格区分文件名大小写)。
- 权限不足:当前运行Python的用户没有读取目标文件或
encrypted文件夹的权限。 - 文件实际不存在:
encrypted文件夹内缺少指定的.dm加密文件。
对应解决方法
验证目录结构:
在脚本所在目录执行以下命令确认文件存在:
Linux/macOS:ls encrypted/Windows:
dir encrypted若输出中没有目标
.dm文件,需检查文件存放路径是否正确。修正文件名拼写:
直接从文件管理器复制目标文件的完整名称到命令行,避免手动输入错误,确保大小写与实际文件一致。修复文件权限:
Linux/macOS下赋予读取权限:chmod -R 644 encrypted/Windows系统右键
encrypted文件夹 → 属性 → 安全 → 确认当前用户拥有「读取」权限。使用绝对路径:
若相对路径始终有问题,直接替换为文件的绝对路径执行,示例:
Linux/macOS:python decryptlg.py /home/yourname/encrypted/njjjAV.jpg.dmWindows:
python decryptlg.py C:\Users\yourname\encrypted\njjjAV.jpg.dm
用户提供的相关代码片段
主逻辑代码:
# get strings from the file header lgeflock, iv, imagestartbyte = get_lgeflock_iv_imagestart(image_path_encrypted) print("lgeflock:", lgeflock.decode('utf-8')) # iv is stored as byte array with length of 16 bytes # iv_hex is stored as hex string with length of 32 chars iv_hex = binascii.hexlify(bytearray(iv)) print("iv:", iv_hex) # open encrypted image as bytes cipher_file = open(image_path_encrypted, "rb") # skip header and iv to image start cipher_file.seek(imagestartbyte) # read from seek to end cipher_body = cipher_file.read() cipher_file.close() print("File information read successfully")
读取文件头的函数:
def get_lgeflock_iv_imagestart(image_path): # open encrypted image as bytes cipher_file = open(image_path, "rb") cipher_header = cipher_file.read(1024) # read only first 1 KB cipher_file.close() # define regex search strings lgeflock_searchstring = b'lge/flock(L[0-9\-_]+@lge.com)' lgeid_searchstring = b'LGEID2.+\r\n' # look up lgeflock: re_lgeflock = re.compile(lgeflock_searchstring) result_lgeflock = re_lgeflock.search(cipher_header) lgeflock = result_lgeflock.group(1)
用户执行的命令:
python decryptlg.py encrypted/njjjAV.jpg.dm python decryptlg.py encrypted/OVOmX4.jpg.dm python decryptlg.py encrypted/photo_1471713808979.jpg.dm python decryptlg.py encrypted/photo_1471815529893.jpg.dm python decryptlg.py encrypted/photo_1471815561014.jpg.dm python decryptlg.py encrypted/PnaXJ5.jpg.dm python decryptlg.py encrypted/qjnjnd.jpg.dm python decryptlg.py encrypted/r66EPz.jpg.dm python decryptlg.py encrypted/VID-20170122-WA0000.mp4.dm python decryptlg.py encrypted/VID-20170125-WA0003.mp4.dm python decryptlg.py encrypted/VID-20170514-WA0001.mp4.dm python decryptlg.py encrypted/VP0WMV.jpg.dm python decryptlg.py encrypted/VP8QZB.jpg.dm python decryptlg.py encrypted/VPP8jV.jpg.dm
内容的提问来源于stack exchange,提问作者Hayalbaz
相关产品推荐
相关产品推荐

