Twine: Can't enter password

Created on 13 Jul 2020  路  23Comments  路  Source: pypa/twine

Your Environment

Thank you for taking the time to report an issue.

To more efficiently resolve this issue, we'd like to know some basic information about your system and setup.

1) Windows 10

2) Python 3.8.2

3) I used pip.(pip install twine)

4) I don't know

5) https://github.com/mathstar13/easyapi

If you're having issues uploading a specific package, you must include a copy of the following:

  • The package's PKG-INFO file
  • A redacted version of your .pypirc file (REMOVE ALL USERNAMES & PASSWORDS BEFORE UPLOADING)

The Issue

The issue is that every time I try to upload, I enter __token__ in username, but I can't enter ANY text in the password field.

Steps to Reproduce

Use wheel on setup.py
Type in python -m twine upload --repository testpypi dist/*
type in __token__ as the username
Try to type in the password

support

Most helpful comment

@sigmavirus24 The four people that reported the issue are https://github.com/pypa/packaging-problems/issues/384 https://github.com/pypa/packaging-problems/issues/376 https://github.com/pypa/packaging-problems/issues/355. Sorry that I was unclear about that. I updated my comment.

All 23 comments

Token had two underscores before and after it.

@mathstar13 The password prompt doesn't show any characters while you type. For the PyPI token, I recommend copying & pasting it when you see the password prompt, and then pressing "Enter". If that doesn't work, can you copy and paste the output from Twine?

Also, I edited your description to make __token__ show up properly.

python -m twine upload --repository testpypi dist/*
Uploading distributions to https://test.pypi.org/legacy/
Enter your username: __token__
Enter your password:
Uploading easyapi_myusername-0.0.1-py3-none-any.whl
100%|鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻坾 6.62k/6.62k [00:00<00:00, 21.4kB/s]
NOTE: Try --verbose to see response content.
HTTPError: 403 Forbidden from https://test.pypi.org/legacy/
Invalid or non-existent authentication information. See https://test.pypi.org/help/#invalid-auth for more information.

If only we had variable debug level logging that could help us validate that the windows version of getpass is working correctly in this case: https://github.com/python/cpython/blob/b4cd77de05e5bbaa6a4be90f710b787e0790c36f/Lib/getpass.py#L97

@mathstar13 Are you sure you're using the token for TestPyPI? As noted at https://test.pypi.org/help/#invalid-auth:

PyPI and TestPyPI each require you to create an account, so your credentials may be different.

If only we had variable debug level logging

@sigmavirus24 I agree that more information about credentials would be useful, which is why I added that to the verbosity roadmap in https://github.com/pypa/twine/issues/381#issuecomment-640955580 yesterday morning.

@bhrutledge I saved it in a file and tried to use it before I created a pypi token. I'm sure then that I used the right one.

@mathstar13 can you validate that the standard library works for you?

python -c 'import getpass; print(getpass.getpass("Test: "))'

Should print whatever you type in even though you won't see it in the terminal as you type it. You don't need to copy/paste it here. Please also test that however you're inputting your token works as well in the same fashion.

@sigmavirus24 When I try to run it, it tells me'

File "<string>", line 1
    'import
          ^
SyntaxError: EOL while scanning string literal

Maybe adjust it for your windows terminal? The example I posted works on a *nix box but I haven't used windows in too long to remember how to write that appropriately

I went down the rabbit hole, installed Windows on a virtual machine, and was able to reproduce this when trying to _paste_ the token in Command Prompt or PowerShell. In short, this is a known issue with getpass (and anything that uses it, like Twine) on Windows. The workarounds include:

  • Clicking Edit > Paste from the Command Prompt menu
  • Enabling Properties > Options > Use Ctrl+Shift+C/V as Copy/Paste in the Command Prompt menu
  • Using the new Windows Terminal

@mathstar13 Can you confirm that one of these works for you?

To reproduce, I copied the text pypi-token, and then ran this code to print the length of the entered value:

C:\Users\brian>python -c "import getpass; print(len(getpass.getpass()))"
Password: <ctrl+v><enter>
1

C:\Users\brian>python -c "import getpass; print(len(getpass.getpass()))"
Password: <ctrl+shift+v><enter>
10

Typing works fine:

C:\Users\brian>python -c "import getpass; print(len(getpass.getpass()))"
Password: pypi-token
10

However, I suspect more folks are running into this due to the use of tokens that are difficult to type.

Aside: the SyntaxError in https://github.com/pypa/twine/issues/671#issuecomment-663778973 is due to the single quote; apparently it needs to be a double quote.

@bhrutledge @sigmavirus24 Thanks for helping me out! I got my package uploaded!

That's great, @mathstar13. Out of curiosity: did one of the workarounds I suggested work for you? If so, which one?

@bhrutledge The one that helped me the best was just the one that showed me getpass. I couldn't paste my token, but I could enter my username and password.

@mathstar13 Oh, I see. So, you just typed your username/password for TestPyPI directly? I was hoping you'd be able to paste your token. Did you try any of the workarounds that I suggested for pasting?

@bhrutledge I couldn't use them because I'm in command prompt, not Windows Terminal.

@mathstar13 One of these options _should_ work from Command Prompt:

  1. Clicking Edit > Paste from the Command Prompt menu
  2. Enabling Properties > Options > Use Ctrl+Shift+C/V as Copy/Paste in the Command Prompt menu
  3. Use right-click to paste

Here's an example of option 1 working for me:

Kapture 2020-08-18 at 12 06 56

In the interest of enabling you to use your token (which is better than username/password) and assisting future Windows Python developers, would you be game to give one of those options a try?

@bhrutledge 1 works fine.

This gotcha feels worth documenting to me, along with a suggested workaround. I can think of a few places to do it, but I'm leaning towards adding it to https://pypi.org/help/#invalid-auth.

@mathstar13 would that have been helpful to you? Do you have other suggestions on where/how to document it?

@di what do you think?

@bhrutledge That would be a good spot to document it. Also, maybe it should be documented in https://packaging.python.org/tutorials/packaging-projects/ if possible. If four people have reported it that I see, maybe others have tried to upload using twine and have been unable to do so.

If four people found it, maybe others can't figure it out.

I don't understand this. Brian and I are both maintainers here. I'm for documenting this, but I'm not sure who the fourth person is here.

@sigmavirus24 The four people that reported the issue are https://github.com/pypa/packaging-problems/issues/384 https://github.com/pypa/packaging-problems/issues/376 https://github.com/pypa/packaging-problems/issues/355. Sorry that I was unclear about that. I updated my comment.

This is now documented at https://pypi.org/help/#invalid-auth.

I'm optimistic that the additional logging in https://github.com/pypa/twine/pull/685 will also help folks diagnose this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sigmavirus24 picture sigmavirus24  路  3Comments

sigmavirus24 picture sigmavirus24  路  8Comments

InAnimaTe picture InAnimaTe  路  5Comments

jonathanunderwood picture jonathanunderwood  路  5Comments

jaraco picture jaraco  路  7Comments