Python 部署到 Azure 应用服务失败且没有错误

时间:2021-04-12 18:07:05

标签: python azure flask azure-web-app-service

我有一个 Python 应用程序,它通过 vscode 和使用 flask run 在本地运行没有问题。

当我尝试使用以下命令将应用程序推送到 Azure 时,它​​失败了:

(.venv) C:\MOS>az webapp up --sku B1 --name mechanics-of-search-api --location "North Europe" -g "mechanics-of-search"
The webapp 'mechanics-of-search-api' doesn't exist
Creating AppServicePlan 'michaelryan998_asp_Linux_northeurope_0' ...
Creating webapp 'mechanics-of-search-api' ...
Configuring default logging for the app, if not already enabled
Creating zip with contents of dir C:\MOS ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
Configuring default logging for the app, if not already enabled
Zip deployment failed. {'id': '748e8415-1c27-484e-94e6-0855a5b6de60', 'status': 3, 'status_text': '', 'author_email': 'N/A', 'author': 'N/A', 'deployer': 'Push-Deployer', 'message': 'Created via a push deployment', 'progress': '', 'received_time': '2021-04-12T17:47:20.5128971Z', 'start_time': '2021-04-12T17:47:21.7678719Z', 'end_time': '2021-04-12T17:47:50.2735201Z', 'last_success_end_time': None, 'complete': True, 'active': False, 'is_temp': False, 'is_readonly': True, 'url': 'https://mechanics-of-search-api.scm.azurewebsites.net/api/deployments/latest', 'log_url': 'https://mechanics-of-search-api.scm.azurewebsites.net/api/deployments/latest/log', 'site_name': 'mechanics-of-search-api'}. Please run the command az webapp log deployment show -n mechanics-of-search-api -g mechanics-of-search

当我尝试在 https://mechanics-of-search-api.scm.azurewebsites.net/api/deployments/latest/log 打开日志时:

{"ClassName":"System.IO.FileNotFoundException","Message":"No log found for 'latest'.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at Kudu.Core.Deployment.DeploymentManager.GetLogEntries(String id) in /tmp/KuduLite/Kudu.Core/Deployment/DeploymentManager.cs:line 112\n   at Kudu.Services.Deployment.DeploymentController.GetLogEntry(String id) in /tmp/KuduLite/Kudu.Services/Deployment/DeploymentController.cs:line 432","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147024894,"Source":"Kudu.Core","WatsonBuckets":null,"FileNotFound_FileName":null,"FileNotFound_FusionLog":null}

如果我执行 az webapp log deployment show -n mechanics-of-search-api -g mechanics-of-search

[
  {
    "details_url": null,
    "id": "a8aa2668-bd08-4617-a48a-731ebd815823",
    "log_time": "2021-04-12T17:47:20.6319438Z",
    "message": "Updating submodules.",
    "type": 0
  },
  {
    "details_url": null,
    "id": "2bebee7b-51a9-4f29-8c23-9ccefbc1c17d",
    "log_time": "2021-04-12T17:47:21.7065948Z",
    "message": "Preparing deployment for commit id '748e8415-1'.",
    "type": 0
  },
  {
    "details_url": null,
    "id": "9cd7ebd1-6aea-4feb-ad90-7461644968dc",
    "log_time": "2021-04-12T17:47:21.9512376Z",
    "message": "Repository path is /tmp/zipdeploy/extracted",
    "type": 0
  },
  {
    "details_url": "https://mechanics-of-search-api.scm.azurewebsites.net/api/deployments/748e8415-1c27-484e-94e6-0855a5b6de60/log/69a4b157-8ddc-492a-ba84-d000bbb545dc",
    "id": "69a4b157-8ddc-492a-ba84-d000bbb545dc",
    "log_time": "2021-04-12T17:47:22.0239278Z",
    "message": "Running oryx build...",
    "type": 2
  }
]

这是我的 requirements.txt 文件:

app==1.0 #Locally defined modules in the project
beautifulsoup4==4.9.3
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
Flask==1.1.2
idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.3
joblib==1.0.1
MarkupSafe==1.1.1
nltk==3.6.1
numpy==1.20.2
progressbar2==3.53.1
python-utils==2.5.6
regex==2021.4.4
requests==2.25.1
six==1.15.0
soupsieve==2.2.1
tqdm==4.60.0
urllib3==1.26.4
Werkzeug==1.0.1
wikipedia==1.4.0

我不知道正在运行什么或如何查找错误所在。我成功部署了 sample project。该项目大约 140MB。

1 个答案:

答案 0 :(得分:0)

通常,故障排除的第一步是使用应用服务诊断:

在 Web 应用程序的 Azure 门户上,从左侧菜单中选择诊断和解决问题。 选择可用性和性能。 检查应用程序日志、容器崩溃容器问题选项中的信息,其中会出现最常见的问题。

https://docs.microsoft.com/en-us/azure/app-service/configure-language-python#troubleshooting

其他注意事项

  1. 确保您位于正确的文件夹中。 az webapp up 应该运行 从包含您的代码的本地文件夹。最常见的错误 正在父目录中运行命令。
  2. 确认您的项目 结构符合“自动 运行时检测逻辑”部分。
  3. 仍有问题?创建 我们存储库中的一个问题: https://github.com/Azure/app-service-linux-docs/issues