How to fix Poetry publish HTTP Error 403: Invalid or non-existent authentication information

Problem:

When you run poetry publish, you get an error like this:

Publishing UliEngineering (0.4.19) to PyPI
 - Uploading uliengineering-0.4.19-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'

Solution

Login to PyPI with poetry (the error message tells you to login again, even if you have already logged in). You need the PyPI API token for this, not your PyPI password. If you don’t have a token, create one on PyPI.

poetry config pypi-token.pypi pypi-.....

Then, try to publish again:

poetry publish --build