在网络共享上打开文件在第6次尝试使用python时失败

在网络共享上打开文件在第6次尝试使用python时失败,python,windows,server,filesystems,Python,Windows,Server,Filesystems,我有一个脚本,可以将数据写入另一台服务器上的文件共享。我正在为网络共享上的单独数据集打开一个单独的文件并保存它。问题是在循环中大约第5个文件之后,打开失败,原因是: Exception has occurred: OSError[Errno 22] Invalid argument: '\\\\file-storage\\storage\\waystar\\active\\ID-143892-Active.txt' File "D:\AGB\test.py", line 7, in <m

我有一个脚本,可以将数据写入另一台服务器上的文件共享。我正在为网络共享上的单独数据集打开一个单独的文件并保存它。问题是在循环中大约第5个文件之后,打开失败,原因是:

Exception has occurred: OSError[Errno 22] Invalid argument: 
'\\\\file-storage\\storage\\waystar\\active\\ID-143892-Active.txt'
File "D:\AGB\test.py", line 7, in <module>
          with open(fn,'w') as f:
我想知道为什么它在列表中最后一个文件上失败。前5项工作正常,已创建。最后一个不是,我得到如上所述的错误22

我添加了一个带有except子句的try块,该子句仅尝试再次打开该文件。这在调试器中有一个有趣的结果。如果我在open之前的except子句中停止它并删除了以前创建的一个文件,那么它将继续创建下一个文件。所以一定有某种限制阻止我一次创建超过5个文件

import os
activedir=r'\\file-storage\storage\waystar\active'
IDs=['123457','123458','123459','143890','143891','143892']
for id in IDs:
    fn=activedir+r'\ID-'+id+'-Active.txt'    
    try:
        with open(fn,'w') as f:
            f.write("Hello World - what a bunch of crap.")
   except:
        with open(fn,'w') as f:
            f.write("Hello World - what a bunch of crap.")
import os
activedir=r'\\file-storage\storage\waystar\active'
IDs=['123457','123458','123459','143890','143891','143892']
for id in IDs:
    fn=activedir+r'\ID-'+id+'-Active.txt'    
    try:
        with open(fn,'w') as f:
            f.write("Hello World - what a bunch of crap.")
   except:
        with open(fn,'w') as f:
            f.write("Hello World - what a bunch of crap.")