Cómo solucionar el error de poetry publish HTTP Error 403: Invalid or non-existent authentication information

Problema:

Tienes la intención de publicar tu paquete en PyPI usando poetry usando un comando como

poetry_publish.sh
poetry publish

Sin embargo, ves el siguiente mensaje de error:

poetry_publish_403.txt
Publishing mypackage (0.1.0) to PyPI
 - Uploading mypackage-0.1.0-py3-none-any.whl FAILED

HTTP Error 403: Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information. | b'<html>\n <head>\n  <title>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.\n \n <body>\n  <h1>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.\n  Access was denied to this resource.<br/><br/>\nInvalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for more information.\n\n\n \n'

Solución

Primero, necesitas crear un token de API de PyPI si aún no tienes uno. La autenticación por usuario/contraseña está obsoleta.

Ahora ejecuta el siguiente comando para configurar poetry:

poetry_config_token.sh
poetry config http-basic.pypi __token__ APITOKEN

donde APITOKEN es el token de API que quieres usar en esta computadora. Deja __token__ tal cual ya que es un nombre de usuario especial que le dice a PyPI que use un token de API en lugar de la antigua y obsoleta autenticación por usuario/contraseña

Debería verse así:

poetry_config_token_example.sh
poetry config http-basic.pypi __token__ pypi-AgEIc[...]

Ahora reintenta la publicación:

poetry_publish_retry.sh
poetry publish

Ejemplo de salida:

poetry_publish_success.txt
Publishing mypackage (0.1.0) to PyPI
 - Uploading mypackage-0.1.0-py3-none-any.whl 100%
 - Uploading mypackage-0.1.0.tar.gz 100%

Echa un vistazo a artículos similares por categoría: Python