You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署至Platform.sh时遭遇YAML配置解析错误求助

Platform.sh部署Python项目时.platform.app.yaml块映射键错误修复

问题概述

部署Python项目到Platform.sh时,推送代码后触发配置文件解析错误,提示.platform.app.yaml文件中块映射未找到预期键,错误定位在文件的12行5列和13行7列。尝试过谷歌搜索、参考社区方案、YAML校验工具格式化、复用《Python Crash Course》配置文件等方法均未解决。

报错信息

E: Error parsing configuration files:
- applications./.platform.app.yaml: Error loading data: while parsing a block mapping
in "/.platform.app.yaml", line 12, column 5
did not find expected key
in "/.platform.app.yaml", line 13, column 7
To git.us-3.platform.sh:wahnombqmn2eg.git
! [remote rejected] HEAD -> main (invalid configuration files)
error: failed to push some refs to 'git.us-3.platform.sh:wahnombqmn2eg.git'

原始配置文件

name: "ll_project"
type: "python:3.12"

relationships:
  database: "db:postgresql"

# The configuration of the app when it's exposed to the web
web:
  upstream:
    socket_family: unix
  commands:
    start: "gunicorn -w 4 -b unix:$SOCKET ll_project.wsgi:application"
  locations:
    "/":
      passthru: true
    "/static":
      root: "static"
      expires: "1h"
      allow: true

# The size of the persistent disk of the application (in MB)
disk: 512

# Set a local read/write mount for logs
mounts:
  logs:
    source: "local"
    source_path: "logs"

# The hooks executed at various points in the lifecycle of the application
hooks:
  build: |
    pip install --upgrade pip
    pip install -r requirements.txt
    pip install -r requirements_remote.txt

    mkdir -p logs
    python manage.py collectstatic --noinput
  deploy: |
    python manage.py migrate --noinput

解决方法

  • 检查缩进一致性:YAML对缩进极其敏感,必须全程使用空格(推荐2个或4个空格,保持统一),禁止混合使用Tab和空格。打开文本编辑器的「显示空白字符」功能,检查12-13行附近的缩进是否存在异常(比如Tab字符、缩进数量不匹配)。
  • 修复块映射结构:错误提示说明13行的内容没有对应的父键,大概率是12行的块映射(比如upstream:或commands:)下的子项缩进错误。确保子键(如socket_family:、start:)的缩进比父键多2个或4个空格,且没有空行破坏结构。
  • 清除隐藏字符:部分文本编辑器可能会插入不可见的特殊字符(如全角空格、换行符),导致YAML解析失败。可以将配置内容复制到纯文本编辑器(如Notepad++、VS Code的纯文本模式)中重新保存。
  • 适配Platform.sh Python 3.12规范:确认web.upstream配置符合Platform.sh Python 3.12的要求,该版本的配置中socket_family: unix是合法的,但需确保其直接隶属于upstream块,没有多余层级。

修正后的示例配置

name: "ll_project"
type: "python:3.12"

relationships:
  database: "db:postgresql"

web:
  upstream:
    socket_family: unix
  commands:
    start: "gunicorn -w 4 -b unix:$SOCKET ll_project.wsgi:application"
  locations:
    "/":
      passthru: true
    "/static":
      root: "static"
      expires: "1h"
      allow: true

disk: 512

mounts:
  logs:
    source: "local"
    source_path: "logs"

hooks:
  build: |
    pip install --upgrade pip
    pip install -r requirements.txt
    pip install -r requirements_remote.txt
    mkdir -p logs
    python manage.py collectstatic --noinput
  deploy: |
    python manage.py migrate --noinput

内容的提问来源于stack exchange,提问作者Jenn Huang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 06:05:57