Python 我们什么时候能拿到;WindowsError:[错误2]系统找不到指定的文件";
在执行以下代码时,我们经常在日志中看到这一点:Python 我们什么时候能拿到;WindowsError:[错误2]系统找不到指定的文件";,python,windows,Python,Windows,在执行以下代码时,我们经常在日志中看到这一点: file_list = os.listdir(os.path.join(path, folder)) for file in file_list: stats = os.stat(os.path.join(path, folder, file)) WindowsError: [Error 2] The system cannot find the file specified: '\\\\sftp2.example.com
file_list = os.listdir(os.path.join(path, folder))
for file in file_list:
stats = os.stat(os.path.join(path, folder, file))
WindowsError: [Error 2] The system cannot find the file specified: '\\\\sftp2.example.com\\homes\\FOLDER\\FILE.PDF' is the sample traceback .
我看不出为什么会发生这种情况,因为我们在上面一行中列出的目录上循环,所以除非出现文件在当时被删除的情况(几分之一秒,但可能性很小),否则我看不出为什么会发生这种情况
这有什么原因吗?我特别想的是,如果SFTP网络出现故障,该怎么办。Windows中出现错误2的原因是什么?我在哪里可以查找可能的原因?直接指定路径有效吗?这是偶然的,它来自生产日志,因此我试图找出发生错误的有效原因。该功能正常工作。该文件可能在调用
listdir
和调用stat
期间被重命名或删除。(包含文件夹时也会发生这种情况。)或者,如果您的CIFS(Samba?)连接断开,可能会报告为找不到文件。前一种情况非常罕见。网络连接报告为未找到文件是我感到困惑的事情。在“网络关闭”的“未找到文件”右侧报告的错误不正确?