麻线每次都要求我输入密码:如何使用.pypirc

时间:2019-09-14 11:45:37

标签: python setuptools twine

我已经安装了pip pypirc,并使用必需的密码设置了~/.pypirc文件。为什么twine每次调用python setup.py时都要求输入密码?

  $twine upload --repository-url https://test.pypi.org/legacy/ dist/*
  Enter your username:

这里是.pypirc

的形式
[distutils] # this tells distutils what package indexes you can push to
index-servers =
  pypi
  pypitest

[pypi]
repository: https://pypi.python.org/pypi
username: myuser 
password: mypwd 

[pypitest]
repository: https://testpypi.python.org/pypi
username: myuser 
password: mypwd 

更新(不包括--repository-url表示:

UploadToDeprecatedPyPIDetected: You're trying to upload to the legacy PyPI site 'https://pypi.python.org/pypi'. Uploading to those sites is deprecated.
 The new sites are pypi.org and test.pypi.org. Try using https://upload.pypi.org/legacy/ (or https://test.pypi.org/legacy/) to upload your packages instead. These are the default URLs for Twine now.
 More at https://packaging.python.org/guides/migrating-to-pypi-org/ .

2 个答案:

答案 0 :(得分:2)

twine upload dist/*

twine upload -r pypi dist/*

twine upload -r pypitest dist/*

据我了解,twine --repository-url <url>甚至没有咨询~/.pypirc。使用-r <name>,它会在~/.pypirc中查找URL,用户名和密码。如果省略-r <name>,则twine将使用~/.pypirc中的第一个存储库。

答案 1 :(得分:0)

我对最终答案很好奇。我遇到了完全相同的问题。 我在主文件夹中有一个包含以下内容的 .pypirc,但在 twine upload -r pypi dist/* 时,它仍然要求提供凭据。

[distutils]
index-servers =
    pypi
    testpypi
    Amplo

[pypi]
username: __token__
password: ***

[testpypi]
username: __token__
password: ***

[Amplo]
repository: https://upload.pypi.org/legacy/
username: __token__
password: ***