简体   繁体   中英

Azure function failing : "statusCode": 413, "message": "request entity too large"

I have an Python script that creates a CSV file and loads it into an Azure Container. I want to run it as an Azure Function, but it is failing once I deploy it to Azure.

The code works fine in Google Colab ( code here minus the connection string). It also works fine when I run it locally as an Azure function via the CLI ( func start command).

Here is the code from the init .py file that is deployed

import logging
import azure.functions as func
import numpy as np
import pandas as pd
from datetime import datetime
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
import tempfile

def main(mytimer: func.TimerRequest) -> None:
    logging.info('Python trigger function.')
    temp_path = tempfile.gettempdir()
    dateTimeObj = datetime.now()
    timestampStr = dateTimeObj.strftime("%d%b%Y%H%M%S")
    filename =f"{timestampStr}.csv"
    df = pd.DataFrame(np.random.randn(5, 3), columns=['Column1','Column2','Colum3'])
    df.to_csv(f"{temp_path}{filename}", index=False)

    blob = BlobClient.from_connection_string(
        conn_str="My connection string",
        container_name="container2",
        blob_name=filename)

    with open(f"{temp_path}{filename}", "rb") as data:
        blob.upload_blob(data)

The deployment to Azure is successful, but the functions fails in Azure. When I look in the Azure Function portal, the output from the Code+ Test menu says

{
  "statusCode": 413,
  "message": "request entity too large"
}

The CSV file produced by the script is 327B - so tiny. Besides that error message I can't see any good information on what is causing the failure. Can anyone suggest a solution / way forward?

Here is the requirements file contents

# Do not include azure-functions-worker as it may conflict with the Azure Functions platform
azure-functions
azure-storage-blob==12.8.1
logging
numpy==1.19.3
pandas==1.3.0
DateTime==4.3
backports.tempfile==1.0
azure-storage-blob==12.8.1

Here is what I have tried.

This article suggests this issue is linked to CORS (Cross Origin Resource sharing) issue. However adding: https://functions.azure.com to my CORS allowed domains in the the Resource sharing menu in the storage settings of my storage account didn't solve the problem (I also republished the Azure function).

Any help, or suggestions would be appreciated.

I tried reproducing the issue with all the information which you have provided and got the same 404 error as below:

在此处输入图像描述

Later after adding a value * in CORS, we can get rid of this issue, below is the fixed screenshot and CORS values:

CORS:

在此处输入图像描述

Test/Run:

在此处输入图像描述

Also we can add the following domain names to avoid 404 error

https://functions.azure.com
https://functions-staging.azure.com
https://functions.azure.com

This will also fix the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM