【发布时间】:2020-06-26 21:39:42
【问题描述】:
我在 Python 3.8(32 位)中有以下脚本:
import sys
import time
from Crypto.Cipher import AES
which_file = str(sys.argv[1])
if which_file == "license_service":
nameoffiles = "C:\\file1.txt"
else:
nameoffiles = "C:\\file2.txt"
file_names = open(nameoffiles, "r")
filenames = file_names.read()
filenames1 = filenames.split(',')
key_location = "path_to_key"
key_to_encrypt = open(key_location, "rb")
key = key_to_encrypt.read()
key_to_encrypt.close()
for x in filenames1:
file_in = open(x, "rb")
nonce, tag, ciphertext = [file_in.read(x) for x in (16, 16, -1)]
cipher = AES.new(key, AES.MODE_EAX, nonce)
data = cipher.decrypt_and_verify(ciphertext, tag)
file_in.close()
file_out = open(x, "wb")
file_out.write(data)
此脚本读取包含需要解密的文件路径的文件,然后解密文件。
问题是在一台电脑(物理机)上完美运行,从不出现故障,而在另一台电脑(虚拟机)上输出如下错误:
Traceback(最近一次调用最后一次): 文件“C:\github\encrypt2\decrypt.py”,第 26 行,在 文件输出 = 打开(x,“wb”) TypeError: coercing to Unicode: need string or buffer, int found
由于代码在一台计算机上运行良好,我不知道我能做些什么来解决这个问题,除了尝试找出计算机配置之间的差异。
找不到任何区别。
【问题讨论】:
-
操作系统/python版本有哪些?
-
python 38 32位,物理是windows 10 2017 enterprise,VM是windows 10 pro 2019
-
在 file_out=open(..) 之前打印 x 看看为什么它是 int 而不是字符串
标签: python python-3.x