I have a blob container and two folders in it.(inputs,outputs)When an excel file is placed in the input folder I want to trigger the function and after compiling the code I want to place the output excel file in the folder named 'outputs'.I'm using python.
I have used input binding to trigger the function.After compiling the code I've done output binding to place the newly created file into output folder.But, it's not happening.
I'm doing this locally using Azure storage emulator and Azure storage explorer.
This is my function.json file.
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "inputblob",
"type": "blobTrigger",
"direction": "in",
"path": "cloudops-resources/inputs/{name}",
"connection": "AzureWebJobsStorage"
},
{
"name": "outputblob",
"type": "blob",
"direction": "out",
"path": "cloudops-resources/outputs/{name}",
"connection": "AzureWebJobsStorage"
}
],
"disabled": false
}
This is my local.settings.json file.
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobs.my_function.Disabled": "true"
}
}
I tried using this code.
This is my init.py
def main(inputblob: func.InputStream, outputblob: func.Out[func.InputStream]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {inputblob.name}\n"
f"Blob Size: {inputblob.length} bytes")
.
.#some code here
.
.
#Reading the input xlsx file from customer
df0 = pd.read_excel(inputblob)
#Opening a new workbook and a worksheet
wb = Workbook()
sheet = wb.active
.
.#some code here
.
#Saving the file
today = date.today()
date_today = today.strftime("%m-%d-%y")
outputblob = "{}_COMPLETE_{}.xlsx".format(date_today,inputblob)
wb.save(outputblob)
return func.Out[func.InputStream](
body=outputblob,
status_code=200
)
I referred to these as well.
Can someone please help me to resolve this issue?
PS: My edited code.
init.py
def main(inputblob: func.InputStream, outputblob:
func.Out[func.InputStream]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {inputblob.name}\n"
f"file: {inputblob}\n"
f"Blob Size: {inputblob.length} bytes")
...some code here...
df0 = pd.read_excel(inputblob.read())
logging.info(f"{df0}")
#Opening a new workbook and a worksheet
wb = Workbook()
sheet = wb.active
...some code here...
#Saving the file
today = date.today()
date_today = today.strftime("%m-%d-%y")
outputfile = "{}_COMPLETE_{}".format(date_today,inputblob.name)
wb.save(outputfile)
outputblob.set(wb)
logging.info(f"Name: {outputblob.name}\n"
f"file: {outputblob}\n"
f"Blob Size: {outputblob.length} bytes")
return()
This doesn't place the output file in the output container and giving an error as well.
System.Private.CoreLib: Exception while executing function: Functions.BlobTrigger. System.Private.CoreLib: Result: Failure Exception: FileNotFoundError: [Errno 2] No such file or directory: '03-29-23_COMPLETE_cloudops-resources/inputs/Input_file123.xlsx' Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 452, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "C:\Users\Asu\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 718, in _run_sync_func
return ExtensionManager.get_sync_invocation_wrapper(context, File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.9/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in raw_invocation_wrapper result = function(**args) File "D:\Service Projects\Customers\InvoiceCompare\BlobTrigger_init.py", line 360, in main wb.save(outputfile) File "D:\Service Projects\Customers\InvoiceCompare\env\lib\site-packages\openpyxl\workbook\workbook.py", line 386, in save save_workbook(self, filename) File "D:\Service Projects-1\Customers\InvoiceCompare\env\lib\site-packages\openpyxl\writer\excel.py", line 291, in save_workbook archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True) File "C:\Users\Asu\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1246, in init self.fp = io.open(file, filemode) .