by no means am i an expert when it comes to python but i have tried my best. I have written a short code in python that reads a text file from a blob storage and appends it with some column names and outputs it to target folder. The code executes correctly when i run from VS Code.
When i try to run it via Azure Function i get it throws an error.
Can it be that i have wrong parameters in my function.json binding file?
{ "statusCode": 500, "message": "Internal server error" }
This is my original code:
import logging
import azure.functions as func
from azure.storage.blob import BlobClient,BlobServiceClient
def main():
logging.info(' start Python Main function processed a request.')
#CONNECTION STRING
blob_service_client = BlobServiceClient.from_connection_string(CONN_STR)
# MAP SOURCE FILE
blob_client = blob_service_client.get_blob_client(container="source", blob="source.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="target", blob="target.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')
if __name__ == "__main__":
main()
This is my function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "blob",
"direction": "in",
"name": "blob_client",
"path": "source/source.txt",
"connection": "STORAGE_CONN_STR"
},
{
"type": "blob",
"direction": "out",
"name": "output_file_dest",
"path": "target/target.csv",
"connection": "STORAGE_CONN_STR"
}
]
}
This is my requirement.txt
azure-functions==1.7.2
azure-storage-blob==12.8.1