簡體   English   中英

相同的 python 腳本在一台計算機上工作,但在另一台計算機上不起作用

[英]Same python script works in one computer but not in another

我在 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)

該腳本讀取一個包含需要解密的文件路徑的文件,然后解密這些文件。

問題是在一台計算機(物理機)上運行完美,永不失敗,在另一台計算機(虛擬機)上輸出如下錯誤:

回溯(最近一次調用):文件“C:\\github\\encrypt2\\decrypt.py”,第 26 行,在 file_out = open(x, "wb") 中 TypeError: coercing to Unicode: need string or buffer, int found

由於代碼在一台計算機上運行正常,我不知道我能做些什么來解決這個問題,除了試圖找到計算機配置之間的差異。

找不到任何區別。

解決了,vm也安裝了python 2.7,卸載后將var path設置為3.8一切正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM