上传PyPI时遭遇Error 405(Method Not Allowed)问题求助
Hey there! That 405 error usually pops up because you're using an outdated upload method that PyPI no longer supports. Let's break down the solution step by step:
Common Cause: Deprecated setup.py upload Command
The old python setup.py upload command has been retired by PyPI—they've blocked this method entirely, which is why you're getting the "Method Not Allowed" response. You need to use twine instead, which is the recommended tool for secure package uploads.
Step-by-Step Fix
Install Twine
First, make sure you have twine installed on your system:pip install twineBuild Your Package
Before uploading, generate the distribution files (source tarball and wheel) using setup.py:python setup.py sdist bdist_wheelThis will create a
dist/folder with your package files ready for upload.Upload with Twine
Now use twine to upload your package to PyPI. You'll be prompted for your PyPI credentials (I recommend using an API token instead of your password for better security):twine upload dist/*
Additional Checks
- If you have a
~/.pypircconfiguration file, double-check that it's pointing to the correct PyPI repository with HTTPS:[pypi] repository = https://upload.pypi.org/legacy/ username = __token__ password = your-pypi-api-token-here - Ensure you're not accidentally targeting a test repository (like test.pypi.org) unless that's intentional—if you are, add the
--repository testpypiflag to the twine command.
That should resolve the 405 error and get your spongebot package up on PyPI!
内容的提问来源于stack exchange,提问作者Javier Jiménez de la Jara

