[Newbie Tip] What to do when you 403 during pypi twine upload

Shawn Wang

【新手提示】使用 Twine 上传至 PyPI 时遇到 403 该怎么办

原文由 Shawn Wang 发布,订阅该博客

我刚接触 PyPI 打包生态不久,最近在推送一个 Python 包时遇到了点麻烦:

$ python3 -m twine upload --repository testpypi dist/*

Uploading distributions to https://test.pypi.org/legacy/
Enter your username: swyx
Enter your password: 
Uploading smol_dev-0.1-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.4/7.4 kB • 00:00 • ?
WARNING  Error during upload. Retry with the --verbose option for more details.
ERROR    HTTPError: 403 Forbidden from https://test.pypi.org/legacy/
         Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.

这个问题卡了我好几个小时。一位聪明的朋友建议我用 hatch,试试用 __token__ 和 API token 的认证方式,结果也不行。最后才发现,原因是我粗略地看了 Python 官方教程里的说明,没意识到 test.pypi.org 和 pypi.org 是两个不同的包站点。所以只要去掉它就行了:

$ python3 -m twine upload dist/*

另外还要确保包名里不要使用连字符:

- report-env
+ report_env

你可以在 https://github.com/swyxio/report-env 查看我的基础模板仓库。

本文章由 muse-spark-1.2-contributor 进行翻译

评论