Aks*_*ase 2 python directory azure-functions
我正在尝试使用 python 的 azure 函数创建一个新的目录文件夹。但我无法在 python 的 azure 函数中创建新的目录和文件。我得到以下错误。
每当我在本地为 python 执行 Azure 函数时,它都可以正常工作,但在 azure 上却不行。
错误: -
Error in folder creation: [Errno 30] Read-only file system: './HttpTrigger/logs'
Run Code Online (Sandbox Code Playgroud)
我试图在 HttpTrigger 函数中创建新的日志文件夹,但出现上述错误。
请检查以下代码:-
import logging
import struct
import sys
import azure.functions as func
import os
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
if not os.path.exists('./HttpTrigger/logs'):
logging.info('Inside Forlder Creation')
os.makedirs('./HttpTrigger/logs')
f= open("test.txt","w+")
for i in range(10):
logging.info('Inside For')
f.write("This is line %d\r\n" % (i+1))
logging.info('Outside For')
f.close()
return func.HttpResponse("Created",
status_code=200
)
except Exception as e:
return func.HttpResponse(f"Error in floder creation : {e}", status_code=400)
Run Code Online (Sandbox Code Playgroud)
有没有办法在azure函数中为python创建一个新目录?如果有什么办法请告诉我。
如果您需要临时进行一些文件处理,则 azure 函数提供了一个临时目录。 天蓝色函数中的临时目录
这是一个代码片段。
import tempfile
from os import listdir
tempFilePath = tempfile.gettempdir()
fp = tempfile.NamedTemporaryFile()
fp.write(b'Hello world!')
filesDirListInTemp = listdir(tempFilePath)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4379 次 |
| 最近记录: |