我正在为我的公司编写一个python代码,用ftplib将许多图像文件上传到FTP服务器,但我的代码必须应用于网络不稳定。因此,当图像文件上载到FTP服务器时,可能会失败,然后我会得到一个错误“ftplib.error\u perm:550该进程无法访问该文件,因为它正被另一个进程使用。”。顺便说一下,FTP服务器由另一家公司管理
我的上传图像文件代码:
with open(img_list[0][0], "rb") as oFile:
check_chars = oFile.read()[-2:]
# End of with-block
if check_chars != b"\xff\xd9":
time.sleep(1)
continue
# End of if-condition
print("準備上傳: %s" %(img_list[0][1]))
if cut_switch:
img = Cut_image(img_list[0][0])
ftp.storbinary('STOR '+img_list[0][1], img)
else:
with open(img_list[0][0], 'rb') as imageReader:
ftp.storbinary('STOR '+img_list[0][1], imageReader)
# End of with-block
# End of if-else-condition
我希望有人能给我一些建议来解决这个错误
试试这个:
发生此错误是因为您尚未关闭文件(正在打开) 您应该记住,您不需要
continue
退出if-else条件相关问题 更多 >
编程相关推荐