Azure Web App部署Python Django应用时出现无法打开manage.py文件报错
Azure Web App 部署Django应用故障排查记录
初始异常表现
作为首次使用Azure部署项目的开发者,在完成Azure DevOps流水线的Django应用构建、发布流程后,对应Azure Web App始终无法正常运行,暂时无法定位问题根因。
在诊断控制台执行py manage.py runserver命令时,收到如下报错:
D:\Python34\python.exe: can't open file 'manage.py': [Errno 0] No error
操作过程中还会随机出现附带报错:
Window title cannot be longer than 1023 characters.
已知项目路径与结构
- 服务器端项目实际存放路径:
D:\home\site\wwwroot\<applicationName> - 实际项目文件目录结构:
wwwroot └── applicationname ├── api ├── applicationname ├── .env ├── db.sqlite3(空文件,未投入使用) ├── manage.py └── requirements.txt
已尝试的排查操作
- 参考Jason Pan的排查思路,在Azure Web App的「配置 -> 路径映射 -> 物理路径」板块调整文件指向路径
- 在
wwwroot/applicationname路径下添加自定义web.config配置文件,调整后触发新的错误:The specified CGI application encountered an error and the server terminated the process.
所使用的web.config配置内容如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/> </handlers> <httpPlatform processPath="D:\home\python364x64\python.exe" arguments="manage.py runserver %HTTP_PLATFORM_PORT%" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true"> <environmentVariables> <environmentVariable name="PYTHONPATH" value="D:\home\site\wwwroot"/> </environmentVariables> </httpPlatform> </system.webServer> </configuration>
最终解决方案
在Jason Pan的协助下,调整部署方案改用Azure Container Service方式上线该Django应用,目前应用运行稳定、功能正常。
内容的提问来源于stack exchange,提问作者Marius Bekk
相关产品推荐
相关产品推荐

