I am developing a Python Azure function and trying to use the Gigya SDK (found here: https://github.com/SAP/gigya-python-sdk) for authentication. However, I am running into an issue where my Azure Function cannot seem to find the GSSDK module when executing.
Here's the error I'm encountering:
Result: Failure Exception: ModuleNotFoundError: No module named 'GSSDK'. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.x/LINUX/X64/azure_functions_worker/dispatcher.py", in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.x/LINUX/X64/azure_functions_worker/utils/wrappers.py", in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.x/LINUX/X64/azure_functions_worker/utils/wrappers.py", in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.x/LINUX/X64/azure_functions_worker
I've placed the GSSDK.py file in a local /lib directory along with my init.py file to mark it as a package. The directory structure looks like this:
/app
| \__inti_\_.py
| GSSDK.py
Here's the start of my init.py script for the Azure Function, where I've attempted to append the directory to sys.path and import the GSSDK module. It didn't work without the sys.path append either:
import azure.functions as func
import json
from azure.storage.blob import BlobServiceClient
import os
import sys
sys.path.append(os.path.dirname(
file
))
from necessary_module import *
Even after these steps, the Azure function cannot locate the required module. The module is not available on PyPi, so it can't be added to requirements.txt.
Would appreciate any advice or guidance.
When I tried using your code to import GSSDK file as module, I received the same error code as yours:-
I tried the below code in my init.py to import GSSDK modules from the file and the Trigger ran successfully.
My init.py:-
import azure.functions as func
# import sys
# import os
import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from GSSDK import *
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
)
My GSSDK referred from here
My requirements.txt:-
azure-functions
My Function Trigger File structure, init.py and GSSDK.py are in same HttpTrigger1 folder rest all the files are outside that folder in root folder, Refer below:-
I deployed this Function in Function app and it ran successfully there:-