[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 進行翻譯

留言