We are building an http trigger using Azure functions.
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
From the online platform, we were able to trigger it by adding a parameter and print it on the screen.
Once we try to import files from src folder which at the same level of HttpTrigger1
,
import src.main
We have the following error:
Error in load_function. Sys Path: ['C:\Users\AliMehdy\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64',
And it points out to main.py
where we have already loaded a library called load_toml
. Also over each import in main.py from src folder.
So it's throwing the same error over each module.
We did check the documentations and specifically that part:
When you're using absolute import syntax, the shared_code/ folder needs to contain an init.py file to mark it as a Python package.
Still, we didn't know what to do. Any idea how to import other modules into Azure http trigger function?