我正在开发一个 lambda 函数,该函数需要在我的文件'my_list'
的一行中写入 list 的每个元素。'upload.txt'
我使用了下一个代码:
my_list=['hello', 'world', 'good', 'morning']
with open("upload.txt", "w+") as a_file:
for item in my_list:
a_file.write("%s\n" % item)
file_dict = {"upload.txt": a_file}
response = requests.post(url, files=file_dict)
当我尝试测试我的 lambda 时,它给了我下一个错误:
"errorMessage": "[Errno 30] Read-only file system: 'upload.txt'",
"errorType": "OSError",
很奇怪,因为我现在将创建该文件,所以为什么它是只读文件
它实际上不允许您编写它;只需使用/tmp/
目录为 lambda 编写临时文件。请记住,/tmp
在并发运行 lambda 时并不总是清理其中的文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句