我正在開發一個 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",
這很奇怪,因為我現在將創建該檔案,所以為什么它是只讀檔案
uj5u.com熱心網友回復:
它實際上不允許您撰寫它;只需使用/tmp/目錄為 lambda 撰寫臨時檔案。請記住,/tmp在并發運行 lambda 時并不總是清理其中的檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/487836.html
