Azure function app 503 Service Unavailable in Code+Test

Amila Ariyasena 1 Reputation point
2021-09-04T10:13:14.843+00:00

Hello,

First I need to say I'm new to Azure function app and this maybe a simple issue.

I have a function app to get csv file from blob and validate the url in a column and then write back the result to blob storage. ( Attached the code)
However, when I'm trying to test in portal I'm getting a 503 Service Unavailable error. But the even in the portal I get 503 I can see the program written the results to the blob storage correctly. ( With the new columns for url validation Line 40-54) . Which means it executed and uploaded the data to blob storage.

Can someone help me with issue.

Thank you in advance

URL
:
https://dataqualitylinkedin.azurewebsites.net
Operating System
:
Linux
App Service Plan
:
ASP-MarketingIntelligence-a8ed (Y1: 0)

Runtime version
:
3. 1.4.0

----------

# Import module for logging purposes  
import logging  
import pandas as pd  
import validators  
import requests  
from   azure.storage.blob import BlobServiceClient  
import io  
# Import module for Azure Functions and give it an alias  
import azure.functions as func  
   
# Main function and entry point of this Azure Function  
def main(req: func.HttpRequest) -> func.HttpResponse:  
              
    # Log information  
    logging.info('Python HTTP trigger function processed a request.')  
    name = req.params.get('name')  
    if not name:  
        try:              
            connection_string=********************  
            #Instantiate a new BlobServiceClient using a connection string  
            blob_service_client = BlobServiceClient.from_connection_string(connection_string)  
            # Instantiate a new ContainerClient  
            blob_client_Input = blob_service_client.get_blob_client(container="container_project", blob="Input.csv")  
  
            headers = {  
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',  
            }  
  
            blob = blob_client_Input.download_blob().content_as_text()  
            dt = pd.read_csv(io.StringIO(blob))  
  
            for i in range(dt.shape[0]):  
                str = dt.iloc[i,3]  
                if not pd.isna(str):  
                    if "http://" in str or "https://" in str:  
                        str     
                    else:   
                        str = "http://"+str  
                      
                    try:  
                        valid=validators.url(str)  
                    except:  
                        valid= "Invalid"  
  
                    if valid==True:  
                        dt.at[i,"Validity"] = "Valid"  
                        try:  
                            response = requests.get(str,headers=headers,timeout=10)  
                            dt.at[i,"Respond"] = "Responsive"  
                        except:  
                            dt.at[i,"Respond"] = "Unresponsive"  
                    else:  
                        dt.at[i,"Validity"] = "Invalid"  
                        dt.at[i,"Respond"] = "Unresponsive"  
                else:  
                    dt.at[i,"Validity"] = "Blank"  
                    dt.at[i,"Respond"] = "Blank"  
  
            dt = dt.replace({'"': ''}, regex=True)  
            dt = dt.to_csv (index=False) #, encoding = "utf-8" This is default)  
  
            container_client = blob_service_client.get_container_client('container_project')  
            try:  
            # Instantiate a new BlobClient  
                blob_client = container_client.get_blob_client("output.csv")  
            # upload data  
                blob_client.upload_blob(dt, blob_type="BlockBlob")  
                return func.HttpResponse(f"Hello, {container_client} . Blob function executed successfully.")      
            except:  
                pass  
            req_body = req.get_json()  
        except:  
            pass  
        else:  
            name = req_body.get('name')  
  
    # Retrieve parameter 'name' from querystring  
    name = req.params.get('name')  
      
    # If a name was found then response with 'Hello [name]'  
    if name:  
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")  
    else:  
        # If a name was not found response with an error message  
        return func.HttpResponse(  
             "Please pass a name on the query string or in the request body",  
             status_code=200  
        )  
  

129269-image.png

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,146 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Alexander Kammerer 121 Reputation points
    2021-10-06T08:22:06.647+00:00

    @MayankBargali-MSFT We observe the same problem for a Function App in the serverless tier (running Python 3.8). We have frequent and irregular 503 errors. Sometimes, we get that the "Azure Functions runtime is unavailable", if we go into the Functions blade in the portal.

    I redeployed the function app yesterday to see if that fixes it but that seems to do nothing.

    1 person found this answer helpful.

  2. MayankBargali-MSFT 70,556 Reputation points
    2021-09-10T04:13:33.887+00:00

    If someone is facing the similar issue it can be transient issue. You can try to define the retry policies and for Trigger like HTTP and timer, don't resume on a new instance. This means that the max retry count is a best effort, and in some rare cases an execution could be retried more than the maximum, or for triggers like HTTP and timer be retried less than the maximum. If it is not Intermittend please tag me in or open a support request with us to assist you further.

    0 comments No comments

  3. vicstr 1 Reputation point
    2021-10-27T12:31:43.017+00:00

    I'm also trying to deploy an azure function and i'm receiving Response status code does not indicate success: 503 (Site Unavailable).

    For the record I'm folowing the Python quickstart tutorial here:
    https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python

    I'm trying this in the context of a fresh Azure account.
    Maybe there's some prior configuration/initialization that I've been missing?

    I've tried with the VScode Extension and also from CLI tools, reproduces 503 the same in both cases.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.