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
)