试图重命名OneDrive的文件时许可
当我运行加密文件的代码时,我会收到以下错误:
<_io.TextIOWrapper name='C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 >(2).png' mode='r' encoding='cp1252'>
read
encrypting
encrypted
encrypted file saved
Traceback (most recent call last):
File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 93, in <module>
encrypt(fpath)
File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 67, in encrypt
os.rename(file_fpath, file_fpath + ".encrypted")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'
以下是我的代码:
fernet = AES(key)
def encrypt(file_path):
#start a timer
start = time.time()
def read_in_chunks(file_object, chunk_size= 52428800):
while True:
data = file_object.read(chunk_size)
if not data:
break
yield data
with open(file_path, "rb") as f:
for piece in read_in_chunks(f):
data = fernet.encrypt(randbytes(16), piece, randbytes(16))
currenttime = time.time()
print(currenttime - start)
with open (file_path + ".enc", "ab") as f:
f.write(data)
f.close()
with open("filenames.txt", "a") as file:
file.write(file_path + "\n")
file.close()
#end the timer
end = time.time()
print ("Time taken to encrypt `: " + str(end - start))
os.remove(file_path)
代码确实加密文件,但剂量不添加。将.centpypted添加到文件名的末尾。
When I run my code that encrypts a file, I get the following error:
<_io.TextIOWrapper name='C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 >(2).png' mode='r' encoding='cp1252'>
read
encrypting
encrypted
encrypted file saved
Traceback (most recent call last):
File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 93, in <module>
encrypt(fpath)
File "c:\Users\depen\OneDrive\Documents\python\timer\encrypt.py", line 67, in encrypt
os.rename(file_fpath, file_fpath + ".encrypted")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png' -> 'C:/Users/depen/OneDrive/Documents/PNG_transparency_demonstration_1 (2).png.encrypted'
Here is my code:
fernet = AES(key)
def encrypt(file_path):
#start a timer
start = time.time()
def read_in_chunks(file_object, chunk_size= 52428800):
while True:
data = file_object.read(chunk_size)
if not data:
break
yield data
with open(file_path, "rb") as f:
for piece in read_in_chunks(f):
data = fernet.encrypt(randbytes(16), piece, randbytes(16))
currenttime = time.time()
print(currenttime - start)
with open (file_path + ".enc", "ab") as f:
f.write(data)
f.close()
with open("filenames.txt", "a") as file:
file.write(file_path + "\n")
file.close()
#end the timer
end = time.time()
print ("Time taken to encrypt `: " + str(end - start))
os.remove(file_path)
The code does encrypt the file but dose not add a .encrypted to the end of the filename.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会遇到此错误,因为您正在使用OneDrive目录。 OneDrive正在尝试同步文件,因此创建文件后,他将尝试上传文件。
尝试从OneDrive不使用的另一个目录执行您的代码
You got this error because you are working on onedrive directory . Onedrive is trying to sync the file so once you create the file , he's trying to upload the file.
Try to execute your code from another directory that onedrive is not using