python - IO错误: [Errno 22] Invalid argument python write

标签 python python-2.7

我正在写入网络共享,这是写入的代码

while not created:
    fileName = ''.join(random.choice(CANDIDATE_CHARS) for x in range(len))
    fullPath = os.path.join(base, fileName)
    if not os.path.exists(fullPath):
        filesize = random.randint(fileSizeLowerLim, fileSizeUpperLim)
        logger.info("Creating file %s, with size %d" %(fullPath, filesize))
        with open(fullPath, 'wb') as fout:
            if filesize > 0:
               fout.write(os.urandom(filesize * 1048576))
               sizeLimit -= filesize
        allFiles.append(fullPath)
        created = True
logger.info("Created file %s, now limit is %d" %(fullPath, sizeLimit))

我收到此错误:

fout.write(os.urandom(filesize * 1048576))
  IOError: [Errno 22] Invalid argument
  job remoteMachine finished ended with rc = 1
  remoteMachine finished and it failed

当我查看文件时,它已生成但没有数据。我在 python 中错过了什么吗?

我正在使用 32 位 python 在 Windows 7 上运行脚本。

最佳答案

我怀疑您的“urandom”缓冲区超过 64MB,因此出现 Windows operating system limit ,这也同样影响了其他人 writing to a network share .

关于python - IO错误: [Errno 22] Invalid argument python write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16366470/

相关文章:

python - 减少 Keras.models.model 内存消耗

python - 如何获得书 "Web Scraping with Python: Collecting Data from the Modern Web"第 7 章数据标准化部分中的相同结果

python - Numpy 和 OpenCV

python - 如何使用 h5py 读取只有数据集(没有组)的 HDF5 文件?

python - 如何向 .loc pandas 动态添加条件

python - 我的 Python 状态机陷入无限循环

python - Pymysql 使用 %s (参数占位符)执行联合查询时

python - : os. listdir ('.' ) 与 os.listdir() 有什么区别

python - 如何解码cp1252字符串?

memory - file.read() 在 64 位 python 上返回超过 2 GB 时出错