Azure / Azure-Functions

1.11k stars 198 forks source link

Result: Failure Exception: OSError: [Errno 38] Function not implemented: Error #2196

Open manish-rocks opened 2 years ago

manish-rocks commented 2 years ago

python function giving error in azure cloud but running locally fine

I have created 1 azure function(time trigger locally) and it was working fine. But when I deployed it on azure using Vs Code and ran then it was giving error like below which I was able to see in monitor tab in azure function: 2022-04-18 11:27:44.021 Result: Failure Exception: OSError: [Errno 38] Function not implemented: 'scraped_json_files/airbnb.json' -> 'scraped_json_files/airbnb2022-04-18_11-27-44.json' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 402, in _handleinvocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 611, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(args) File "/home/site/wwwroot/scraper_timer_trigger/init__.py", line 35, in main os.rename(path,new_file_path).

below is the code of init.py file of the function.

    import datetime
    from distutils.log import log
    import logging
    import os
    import azure.functions as func

    def main(mytimer: func.TimerRequest) -> None:
        utc_timestamp = datetime.datetime.utcnow().replace(
            tzinfo=datetime.timezone.utc).isoformat()

        if mytimer.past_due:
            logging.info('The timer is past due!')

        logging.info('Python timer trigger function ran at %s', utc_timestamp)
        # os.system('echo "change directory to propertyscraper project"')
        # os.system('cd ./propertyscraper')
        # ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
        os.system('echo "*****************************************************"')
        logging.info(os.getcwd())
        # os.system("echo $PWD")
        logging.info(f"curret dir: {os.getcwd()}" )

        logging.info("create directory: scraped_json_files")
        os.makedirs("scraped_json_files", exist_ok=True)

        os.system('echo "run airbnb spider"')
        path = os.path.join("scraped_json_files","airbnb.json")
        os.system(f"scrapy crawl airbnb -o {path}")
        logging.info(f"current dir files:{os.listdir()}")
        logging.info(f"previous dir files: {os.listdir('..')}")

        file_creation_time = datetime.datetime.now().strftime(f'%Y-%m-%d_%H-%M-%S')
        new_file_path = os.path.join("scraped_json_files","airbnb"+file_creation_time+".json")
        # os.rename(path, f"./scraped_json_files/airbnb{file_creation_time}.json")
        os.rename(path,new_file_path)
        # os.rename("./scraped_json_files/airbnb.json", "scraped_json_files/airbnb_"+file_creation_time+".json")

below is the project structure which I have created locally in vs code.

image

in this image scraper_timer_trigger is the azure function name. scraper_function is the scrapy project. and other directories for storing files etc.

guys plz help what am I doing wrong in here.

v-bbalaiagar commented 2 years ago

Hi @vrdmr , Could you please look into this issue.

alimehdy1990 commented 1 year ago

hello. did anyone reach a solution as I am having the same issue with adding folders using makedirs()

eperaza commented 1 year ago

getting same error... any update?

kushmp commented 2 months ago

@v-bbalaiagar @vrdmr - could you please update this issue? I am facing the same issue.

theriny commented 2 months ago

I'm now getting the same error. Thing is, the code ran fine in Azure for several days. I updated the code to try implementing a new function which was unsuccessful. After reverting back to the original code, I'm now getting this error.

I've noticed that sometimes the first few runs of a triggered function app can result in errors, but eventually the problem "fixes" itself. There seems to be some issues with installing the python packages from the requirements.txt document. Hopefully, the problem fixes itself.