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

GitHub Actions发布Python包至Test PyPI遇400错误求助

问题:GitHub Actions自动化发布Python包到Test PyPI触发400 Bad Request错误

我按照官方教程配置GitHub Actions自动化发布Python包到Test PyPI,当前使用的release.yml配置文件如下:

name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
  build:
    name: Build distribution 📦
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: "3.11"
    - name: Install pypa/build
      run: >-
        python3 -m
        pip install
        build
        --user
    - name: Install dependencies and Run tests
      run: |
        python -m pip install --upgrade pip
        python -m pip install .
        python -m pip install -r test/requirements.txt
        pytest test
    - name: Build a binary wheel and a source tarball
      run: python3 -m build
    - name: Store the distribution packages
      uses: actions/upload-artifact@v4
      with:
        name: python-package-distributions
        path: dist/

  publish-to-testpypi:
    name: Publish Python 🐍 distribution 📦 to TestPyPI
    needs:
    - build
    runs-on: ubuntu-latest

    environment:
      name: testpypi
      url: https://test.pypi.org/p/mypkg

    permissions:
      id-token: write

    steps:
    - name: Download all the dists
      uses: actions/download-artifact@v4
      with:
        name: python-package-distributions
        path: dist/
    - name: Publish package distributions to TestPyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/

我已在PyPI网站配置可信发布者,无需指定API令牌。推送新提交后出现如下错误:

ERROR    HTTPError: 400 Bad Request from https://test.pypi.org/legacy/           
         Bad Request 

开启verbose参数后,错误信息更明确:

INFO     dist/torchdde-0.1.0-py3-none-any.whl (35.2 KB)                         
INFO     dist/torchdde-0.1.0.tar.gz (23.1 KB)                                   
INFO     password set by command options                                        
INFO     username: __token__                                                    
INFO     password: <hidden>                                                     
Uploading torchdde-0.1.0-py3-none-any.whl
INFO     Response from https://test.pypi.org/legacy/:                           
         400 Bad Request                                                        
INFO     <html>                                                                 
          <head>                                                                
           <title>400 Bad Request</title>                                       
          </head>                                                               
          <body>                                                                
           <h1>400 Bad Request</h1>                                             
           The server could not comply with the request since it is either       
         malformed or otherwise incorrect.<br/><br/>                            
         POST body may not contain duplicate keys                               
                                                                                
                                                                                
          </body>                                                               
         </html>                                                                
ERROR    HTTPError: 400 Bad Request from https://test.pypi.org/legacy/           
         Bad Request     

目前未找到解决方案,恳请提供建议。另外说明:当前master分支版本为0.1.0,此前通过CLI成功发布过0.0.1版本,不确定是否为版本问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 04:27:24