【Azure Function】FTP上传了Python Function文件后,无法在门户页面加载函数的问题
问题描述
通过FTP的方式,把本地能正常运行的Python Function文件上传到云上后,无法加载函数列表问题。
1:上传 function_app.py,requirements.txt文件到 wwwroot 目录中
2:在Azure Function App的Overview页面,无法显示函数列表

3:查看所有日志,无任何异常信息,Docker 日志中显示Host启动成功,function host的日志中,没有错误显示,但记录 0 functions load
### LogFiles/2024_11_21_pl0sdlwk000620_docker.log 日志显示:
2024-11-21T12:28:35.622Z INFO - Pulling image: mcr.microsoft.com/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 mcr.microsoft.com/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=https://portal.azure.cn -e ....... Host.UseFileLogging=true
2024-11-21T12:28:36.697Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/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/2024-11-20T12-56-11Z-1ffcb4d1cf.log 日志显示:
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
这是一个什么情况呢?
问题解答
在遇见此问题后,百思不得其解,最后采用了最笨的办法。逐行/逐段的删除代码,一次一次的查找到底是什么代码导致了这个问题。
先使用一个近似于模板的Python Http Trigger 代码,没有任何多余引用的情况下,函数加载成功!

基于此次发现,一行一行的添加代码,终于,在本次实验中,添加到 import requests 时候,复现问题。
瞬间,明白了原因,函数无法被加载在Overview显示的原因是缺少了 requests module,虽然在 requirements.txt 中添加了requests module,但是Function App并没有帮助安装。
所以,解决问题之法就是本地上传所需要的相关依赖包!
解决办法
第一步:在本地安装 requirements.txt 中的依赖包到.python_packages文件夹中
使用下面的命令,把依赖包安装到 ".python_packages/lib/site-packages" 文件夹中
python -m pip install -r .\requirements.txt --target=".python_packages/lib/site-packages"

第二步:把 .python_packages 文件夹中的内容通过FTP上传 Function App的wwwroot目录中

第三步:重启应用,等待5-10分钟后,刷新Function Overview,成功加载出函数列表!

如此,问题解决!完美收工。
参考资料
使用 FTP/S 将应用部署到 Azure 应用服务 : https://docs.azure.cn/zh-cn/app-service/deploy-ftp?tabs=portal
Install local packages : https://learn.microsoft.com/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" -r requirements.txtWhen 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.
【完】
【Azure Function】FTP上传了Python Function文件后,无法在门户页面加载函数的问题的更多相关文章
- Jenkins通过FTP上传站点太多文件导致太慢且不稳定,切换为压包上传再解压的思路(asp.net)
在本地先处理好要上传的站点文件之后,可能会因为一些网页切图导致ftp上传不稳定,中断,或者文件占用的问题. 那么换了一种实现思路,要借助jenkins的工具jenkins-cli.jar. 解决思路: ...
- 批处理向FTP上传指定属性的文件 批处理增量备份的例子
使用windows批处理向FTP上传具有指定属性的文件,类似增量备份功能. 对一个目录里的几个文件自动上传FTP时只上传有归档属性的文件,然后FTP上传成功后自动清除(本机)刚上传文件的归档属性. 类 ...
- FTP上传文件服务器python实现
总结 使用Python的socket和socketserver模块实现ftp文件服务器.不是很难,但在粘包的问题上纠缠了不少时间.解决办法是发送文件信息之后等待一段时间. #!/usr/bin/pyt ...
- 20160113006 asp.net实现ftp上传代码(解决大文件上传问题)
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using S ...
- FTP上传下载--python
import socket import struct import json import subprocess import os class MYTCPServer: address_famil ...
- selenium+python登录登出百度,等待页面加载,鼠标定位
#coding:gbk from selenium import webdriver from selenium.webdriver.common.keys import Keys from sele ...
- vb.net FTP上传下载,目录操作
https://blog.csdn.net/dzweather/article/details/51429107 FtpWebRequest与FtpWebResponse类用来与特定FTP服务器进行沟 ...
- ftp上传html文件
在用ftp上传当个html文件时,发现html文件会被压缩成一行,在html中的单行注释将后面的代码都注释掉了,导致网页不能正常访问. 8uftp.FlashFXP.filezilla 在这三个ftp ...
- js页面加载的几种方式的速度: window.onload、 $(window).load、 $(function(){})、 $(document).ready(function () {})、onload=‘asd()’
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- python之实现ftp上传下载代码(含错误处理)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之实现ftp上传下载代码(含错误处理) #http://www.cnblogs.com/kait ...
随机推荐
- 编译 Qt 项目
参考:Qt 编程指南 一个最小化工作示例:qt-minimal | GitHub 源文件 main.cpp #include <QApplication> #include <QLa ...
- Prism:框架介绍与安装
Prism:框架介绍与安装 什么是Prism? Prism是一个用于在 WPF.Xamarin Form.Uno 平台和 WinUI 中构建松散耦合.可维护和可测试的 XAML 应用程序框架 Gith ...
- C#项目—模拟考试
C#模拟考试软件 开发了一个<模拟考试>的小软件,此小软件练习的目的主要是为了体会编程思想,深度理解高内聚.低耦合,掌握编程思维逻辑的大招,告别垃圾代码,重点体会编程之美,练习时长30分钟 ...
- c程序设计语言 by K&R(三)结构
一.类型定义 typedef typedef int Length; typedef char* String; typedef struct tnode* Treeptr; typedef int ...
- Angular 18+ 高级教程 – Component 组件 の Attribute Directives 属性型指令
介绍 指令就是没有模板的组件.除了模板其它的都有,比如 selector.inject.@Input.lifecycle 等等. 那既然都有完整的组件了,为什么还搞一个少掉模板的指令呢? 很简单啊,因 ...
- CSS – Icon
前言 Icon 并不容易搞. 市场有许多平台支持 Icon, 有些收费有些免费. 有些 icon 很丰富, 有些很缺失. 尤其是在做网站的时候寻找 icon 是一个挺累的事情. 这篇就来聊聊 icon ...
- DatetimeFormatter字符串转日期
在Java中,我们经常需要将字符串形式的日期时间转换为LocalDateTime.LocalDate.LocalTime等日期时间对象,或者将日期时间对象转换为字符串.为了完成这些操作,我们可以使用D ...
- AJAX——简介
AJAX 同步与异步 AJAX 快速入门
- [namespace hdk] ordered_vector
功能: 已重载[]运算符 已重载+运算符(合并) 已重载+=运算符 已重载构造函数 clear() it() 以std::vector形式返回自身 print(char=' ',char='\n') ...
- 安卓Android虚拟机分享及使用
不知道大家伙在安装安卓虚拟机时被各式各样的问题折磨过没,我在安装安卓虚拟机时,遇到的问题简直就像长江之水源源不断,就算是最后安装好了也会因为各式各样的原因无法进入启动桌面. 当我发现这个可以直接导入到 ...