Azure Function - HTTP response code 500 Internal Server Error

mandania 156 Reputation points
2021-08-16T09:00:19.033+00:00

Hi,

I have written a small python code that reads a file from a blob storage container and appends it in the same container.

When i run it on my local machine, the column names are appended correctly and the code executes without error.

When i deploy it to azure function and then run it from there , i get "HTTP response code 500 Internal Server Error"

I am not proficient in python or azure function but my guess is my binding file is not correctly configured or something else. Would really appreciate if someone could cast an extra pair of eyes and see where i am making a mistake.

Thank you !

-------------------------------------------------PYTHON CODE------------------

import logging
from types import TracebackType

import azure.functions as func

from azure.storage.blob import BlobClient,BlobServiceClient

def main():

try:  
    logging.info(' start Python Main function processed a request.')

    #CONNECTION STRING
    blob_service_client = BlobServiceClient.from_connection_string("CONN_STR==;EndpointSuffix=core.windows.net")

    # MAP SOURCE FILE
    blob_client = blob_service_client.get_blob_client(container="sie", blob="SIE_SHORT.txt")

    #SOURCE CONTENTS
    content=  blob_client.download_blob().content_as_text()

    # WRITE HEADER TO A OUT PUTFILE
    output_file_dest = blob_service_client.get_blob_client(container="sie", blob="SIEOUTPUT.csv")

    #INITIALIZE OUTPUT               
    output_str = ""

    #STORE COULMN HEADERS
    data= list()

    data.append(list(["COLUMN1", "COLUMN2", "COLUMN3", "COLUMN4"]))

    output_str += ('"' + '","'.join(data[0]) + '"\n')

    output_file_dest.upload_blob(output_str,overwrite=True)

    logging.info(' END OF FILE UPLOAD')

except Exception as ex:
    print('Unable to connect!')
    print('Exception:')
    print(ex)
    logging.error(ex)

if name == "main":
main()

----------------------------------------FUNCTION.JSON-------------------

{
"scriptFile": "init.py",
"bindings": [
{
"type": "blob",
"direction": "in",
"name": "blob_client",
"path": "sie/SIE_SHORT.txt",
"connection": "AzureWebJobsStorage"
},
{
"type": "blob",
"direction": "out",
"name": "output_file_dest",
"path": "sie/SIEOUTPUT.csv",
"connection": "AzureWebJobsStorage"
},
{
"name": "$return",
"direction": "out",
"type": "http"
}
]
}
---------------------------------------REQUIREMENT.TXT--------------------------

azure-core==1.17.0
azure-functions==1.7.2
azure-storage-blob==12.8.1


Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,677 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,016 Reputation points
    2021-08-16T10:49:56.06+00:00

    @mandania As you have confirmed that your same code works locally but when deployed to azure function you receives 500 error. In that case looks like there might be some configuration in your local.setting.json that might not be created under the application setting in azure function.

    I will also suggest you to review Azure Functions diagnostics to find the root cause of the 500 error. Alternative you can also review your application insights logs for your function to know more about the full exception trace/error message that is causing 500 error.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful