25

I have pip installed pypirc and set up a ~/.pypirc file with the requisite password. Why is twine asking for a password each time python setup.py is invoked?

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

Here is the form of the .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 

Update Not including the --repository-url gives:

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/ .
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • 1
    How could we guess without looking at your `~/.pypirc`? Also to use `~/.pypirc` you should pass `--repository name`, not `--repository-url url`. – phd Sep 14 '19 at 12:14
  • @phd The references to `twine` that I had found used the form above: `--repository-url ` and not `--repository name` . I do not have an example for the latter. – WestCoastProjects Sep 14 '19 at 12:29
  • @phd The `twine` docs support the format included in the question: https://pypi.org/project/twine/ Can you provide info and/or reference on why a different format is preferred? – WestCoastProjects Sep 14 '19 at 12:38
  • 1
    Ah, sorry, my bad. `-r `. AFAIU `twine --repository-url ` doesn't even consult `~/.pypirc`. With `-r ` it lookups `~/.pypirc` for the URL, user name and password. If you omit `-r `, `twine` uses the first repo from `~/.pypirc`. – phd Sep 14 '19 at 12:56
  • The warning is because you've got the old URLs in `.pypirc`. Do what it says. – OrangeDog Nov 17 '21 at 17:34

3 Answers3

22
twine upload dist/*

or

twine upload -r pypi dist/*

or

twine upload -r pypitest dist/*

As far as I understand twine --repository-url <url> doesn't even consult ~/.pypirc. With -r <name> it lookups ~/.pypirc for the URL, user name and password. If you omit -r <name>, twine uses the first repo from ~/.pypirc.

phd
  • 82,685
  • 13
  • 120
  • 165
  • I tried the first one multiple times and it does not work. I have not tried the `-r` yet: will lyk. – WestCoastProjects Sep 14 '19 at 17:41
  • `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/ .` – WestCoastProjects Sep 14 '19 at 22:31
  • 3
    In `~/.pypirc`: `repository: https://upload.pypi.org/legacy/` or `repository: https://test.pypi.org/legacy/`. – phd Sep 14 '19 at 23:32
  • ah ok. as you mentioned i should have included contents of `/.pypirc` – WestCoastProjects Sep 15 '19 at 03:39
4

Method 1:

python -m twine upload  dist/* -u%username% -p%password%

you can

set username="token"

set password="pypi-AgEIc..."

OR

set username=pypi name

set password=pypi password

Ujjwal Agrawal
  • 830
  • 1
  • 8
  • 14
wen he
  • 41
  • 2
-1

just locate the .pypirc in c:\user\your-name
it will work...

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 27 '21 at 20:41