在 Azure 存储帐户中附加到文件失败

时间:2021-04-16 17:56:50

标签: python azure azure-storage

我正在尝试为 Azure Databrick 中的操作编写日志文件。日志文件将写入 Azure 存储帐户中的文件。我正在使用 Python 来做到这一点。作为测试,我设置了 2 个写操作。第一个写入微秒时间戳的日志文件,该名称基本上保证是唯一的。第二次尝试写入同一目录中名为“log”的文件,并且应该简单地将新的日志行附加到文件中已有的日志行。这是非常简单的代码:

log_file = log_dir + '/' + 'log_' + str(log_ts)
with open(log_file, 'a') as l:
  l.write('\n'.join(log_lines_list))
  
log_file = log_dir + '/' + 'log'
with open(log_file, 'a') as l:
  l.write('\n'.join(log_lines_list))

在我看来,可能会出错的地方并不多。第一个文件已创建并正确写入。第二个是不变的,即使是时间戳也保持不变;也就是说,代码的第一次运行(文件创建)有效,但后续运行(文件追加)失败并显示以下错误:

OSError: [Errno 95] Operation not supported
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
OSError: [Errno 95] Operation not supported

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<command-2639275445480394> in <module>
     45 log_file = log_dir + '/' + 'log'
     46 with open(log_file, 'a') as l:
---> 47   l.write('\n'.join(log_lines_list))

OSError: [Errno 95] Operation not supported

我的研究基本上得出结论,追加操作在这种类型的存储中无效。是对的吗?这对我来说似乎很奇怪,但我对此很陌生。我想我可以将文件读入列表,将新行附加到列表中,重命名文件,并将加入的列表写入以前名称的文件,并在确认写入后删除重命名的文件,但这似乎过多的。我在这里遗漏了什么吗?

0 个答案:

没有答案