Write files in subdirectory of installed dependency in python azure function

Viewed 44

I have a python azure function. In this function, I am using a third-party package, which reads the file from a default path based of the id which is provided while calling library functions.

Now, the default file read path could/couldn't be modified and hence, I am going to write the file in the default path itself via open(f'{defaultFilePath}/filename.xml', "w+" ). Once the file is written, the library will automatically able to read it via default path.

Here the catch is, the default file read path of library is something like /Users/JackSparrow/Desktop/azure-functions/azure-func/.venv/lib/site-package/library-name/XML. So, can I write this file to this location ?

It is working on local machine, but once deployed to azure-function-app it throwing error. ex. Result: Failure Exception: OSError: [Errno 38] Function not implemented:

Sample Code

import logging
import azure.functions as func
import os
from library.settings import WORKING_DIRECTORY


def main(myblob: func.InputStream):
    blob_name = myblob.name.split("/")[1]
    logging.info(f"\n execution started for blob {blob_name}\n")

    ########### --------> Write data to exprected location  <-------- ###########
    try:
        file_text_content = myblob.read()
        DESTINATION_FILE_PATH = os.path.join(WORKING_DIRECTORY, blob_name)
        with open(DESTINATION_FILE_PATH, "wb") as opened_file: # on this line it throws error (I guess)
            opened_file.write(file_text_content)
    except Exception as e:
        logging.info("\n Exception in File Writing \n")
        logging.info(e)
0 Answers
Related