我有 Flask Web 应用程序,我正在尝试在 azure 上发布。我将其部署在网络应用程序上,创建新资源,下载用户发布配置文件并使用下载的文件从 Visual Studio 发布它。一切都在本地主机上顺利运行,但一旦发布,我就会收到错误:
- IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
- IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
- IIS was not able to process configuration for the Web site or application.
- The authenticated user does not have permission to use this DLL.
- The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
我几乎不知道这意味着什么。这是我发布的第一个网站,所以我还是个新手。
My Views.py 使用以下代码调用 senna-win32.exe:
senna_path = os.path.join('senna\\senna-win32.exe')
p = subprocess.Popen(senna_path, stdout=subprocess.PIPE,stdin=subprocess.PIPE)
grep_stdout = p.communicate(input=bytes(va, 'utf-8'))[0]
inList = grep_stdout.decode()
inList = list(inList.splitlines())
我的本地主机上似乎没有问题/错误,但不确定 azure 发生了什么。
最佳答案
根据我的经验,有很多原因会导致像您这样的问题。
对于第一种情况,reqirements.txt 文件中所需的一些 Python 包并未直接安装在 Azure WebApp 上。对于这种情况,您需要按照 troubleshooting 的官方教程进行操作。来解决它。或者甚至,您可以尝试按照我的其他 SO 线程的解决方案 Publishing MVC app that uses python script来解决它。
但是,我认为您的问题可能是由于代码中的 senna_path
不是 Azure WebApp 上的有效路径引起的。我尝试创建一个简单的 Python 脚本,如下所示,以使用 Azure WebApp 上的 Kudu 控制台测试您的代码,它通过命令 python test.py > test.out.txt
运行良好。
import os
from subprocess import Popen, PIPE
path = os.path.join('senna-win32.exe')
p = Popen(path, stdin=PIPE, stdout=PIPE)
grep_stdout = p.communicate(input="happy time".encode('utf-8'))[0]
inList = grep_stdout.decode()
inList = list(inList.splitlines())
print inList
所以我的建议是尝试使用绝对路径D:\home\site\wwwroot\FlaskWebProject1\senna\senna-win32.exe
而不是senna\senna-win32。 exe
为您的应用解决问题。
如有任何更新,请随时告诉我。
关于python - 在 Azure 上发布 Flask Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41785517/