Description of the problem
Problem of not being able to load the list of functions after uploading a locally working Python Function file to the cloud via FTP.
1: Upload function_app.py, file to wwwroot directory
2: On the Overview page of the Azure Function App, the list of functions cannot be displayed
3: Check all the logs, there is no abnormal information, the Docker log shows Host startup success, function host's log, there is no error display, but record 0 functions load
### LogFiles/2024_11_21_pl0sdlwk000620_docker.log Log display:
2024-11-21T12:28:35.622Z INFO - Pulling image: /appsvc/middleware:stage6
2024-11-21T12:28:36.520Z INFO - stage6 Pulling from appsvc/middleware
2024-11-21T12:28:36.533Z INFO - Digest: sha256:
2024-11-21T12:28:36.536Z INFO - Status: Image is up to date for /appsvc/middleware:stage6
2024-11-21T12:28:36.569Z INFO - Pull Image successful, Time taken: 0 Seconds
2024-11-21T12:28:36.696Z INFO - Starting container for site
2024-11-21T12:28:36.697Z INFO - docker run -d --expose=8181 --name lbfunbyftp01_5_6c1bcea1_middleware -e WEBSITE_CORS_ALLOWED_ORIGINS= -e ....... =true
2024-11-21T12:28:36.697Z INFO - Logging is not enabled for this container.
Please use /lin2024-11-21T12:28:37.758Z INFO - Initiating warmup request to container lbfunbyftp01_5_6c1bcea1 for site lbfunbyftp01
2024-11-21T12:28:43.089Z INFO - Container lbfunbyftp01_5_6c1bcea1 for site lbfunbyftp01 initialized successfully and is ready to serve requests.
2024-11-21T12:28:43.089Z INFO - Initiating warmup request to container lbfunbyftp01_5_6c1bcea1_middleware for site lbfunbyftp01
2024-11-21T12:28:43.415Z INFO - Container lbfunbyftp01_5_6c1bcea1_middleware for site lbfunbyftp01 initialized successfully and is ready to serve requests.
### ... /LogFiles/Application/Functions/Host/ Log display:
2024-11-21T12:29:12.670 [Information] Loading functions metadata
2024-11-21T12:29:12.670 [Information] Reading functions metadata (Custom)
2024-11-21T12:29:12.671 [Information] 0 functions found (Custom)
2024-11-21T12:29:12.671 [Information] 0 functions loaded
What kind of a situation is this?
Problem solving
After encountering this problem and puzzling over it, I finally resorted to the dumbest way possible. Delete the code line by line/segment by segment, one at a time, to find out what code is causing the problem.
Starting with an approximation of the template Python Http Trigger code, the function loads successfully without any extra references!
Based on this discovery, I added code line by line, and finally, in this experiment, the problem was reproduced when I added import requests.
Instantly, I understood the reason, the reason why the function could not be loaded in the Overview display was because the requests module was missing, although the requests module was added in, the Function App did not help to install it.
So, the solution to the problem is to locally upload the relevant dependency packages needed!
method settle an issue
Step one:Locally install the dependencies in the .python_packages folder.
Use the following command to install the dependency packages into the ".python_packages/lib/site-packages" folder
python -m pip install -r .\ --target=".python_packages/lib/site-packages"
Step 2: Upload the contents of the .python_packages folder to the wwwroot directory of the Function App via FTP
Step 3: Restart the app and wait for 5-10 minutes to refresh the Function Overview and load out the function list successfully!
So, problem solved! Perfectly wrapped up.
bibliography
Function not found after deployment :/zh-cn/azure-functions/recover-python-functions?tabs=vscode%2Cbash&pivots=python-mode-configuration#functions-not-found-after-deployment
Deploying Applications to Azure Application Services using FTP/S :./zh-cn/app-service/deploy-ftp?tabs=portal
Install local packages : /en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&pivots=python-mode-decorators#install-local-packages
If your project uses packages that aren't publicly available to our tools, you can make them available to your app by putting them in the __app__/.python_packages directory. Before you publish, run the following command to install the dependencies locally:
pip install --target="<PROJECT_DIR>/.python_packages/lib/site-packages" -rWhen you're using custom dependencies, you should use the --no-build publishing option, because you've already installed the dependencies into the project folder.
func azure functionapp publish <APP_NAME> --no-buildRemember to replace <APP_NAME> with the name of your function app in Azure.
[End]