Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error messages with missing config file #564

Closed
pe2mbs opened this issue Jan 25, 2020 · 13 comments · Fixed by #770
Closed

Confusing error messages with missing config file #564

pe2mbs opened this issue Jan 25, 2020 · 13 comments · Fixed by #770

Comments

@pe2mbs
Copy link

pe2mbs commented Jan 25, 2020

Update 6/17/2021: After discussion/troubleshooting of the original issue, a possible resolution seems to be more helpful error and warning messages for missing configuration files; see #564 (comment).


  1. Your operating system:
    Linux matrix 4.15.0-72-generic Restrict requests to at least 2.0 #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

  2. Version of python you are running:
    Python 3.6.9

  3. How did you install twine? Did you use your operating system's package manager or pip or
    pip 19.0.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

  4. Version of twine you have installed (include complete output of):
    twine version 3.1.1 (pkginfo: 1.5.0.1, requests: 2.21.0, setuptools: 39.0.1,
    requests-toolbelt: 0.8.0, tqdm: 4.19.5)

  5. Which package repository are you targeting?
    https://upload.pypi.org/legacy/

The Issue

I added to the .pypirc in my home folder

[forwarder]
username = __token__
password = pypi-Ag............

But when i upload the package to the repository it asks for my username/password.

Steps to Reproduce

When i to

twine upload ./dist/* --config-file ${HOME}/.pypirc

I get the same result
When i copy the ${HOME}/.pypirc to my project folder

twine upload ./dist/* --config-file ./.pypirc

Same result

@pe2mbs pe2mbs changed the title .pypirc in HOME folder doesn't work as expected .pypirc doesn't work as expected Jan 25, 2020
@bhrutledge
Copy link
Contributor

I think Twine is asking for credentials because it's not finding a match for the default pypi repository. I believe you need to change [forwarder] to [pypi].

Alternatively, you can specify the repository name as an argument:

twine upload --repository forwarder ./dist/*

@di
Copy link
Member

di commented Jan 25, 2020

I think @bhrutledge is right. I'm also curious what you expected to happen, @pe2mbs. Is forwarder the name of your package?

@bhrutledge
Copy link
Contributor

Actually, it looks like the --repository forwarder variant doesn't work as expected; see #496 (comment).

That said, I still think changing [forwarder] to [pypi] will work.

@pe2mbs
Copy link
Author

pe2mbs commented Jan 26, 2020

forwarder is the name of the repository.
I expected that twine retrieves the token from the .pypirc file so that i do not have to enter my credentials. I will add --repository forwarder to my publish script and see if that solves the problem.

@pe2mbs
Copy link
Author

pe2mbs commented Jan 26, 2020

Right, adding --repository forwarder didn't solve the problem.

I think i have the wrong thing about this, i was expecting that in the .pypirc file you could define username/password per package to upload the pypi.

When i configured:

[pypi]
username: pe2mbs
password: ****************************

It worked. And when i configured

[pypi]
username: __token__
password: pypi-AgEI*****************************************************

It worked as well.
But what i don't understand is how to set a __token__ per package.

@bhrutledge
Copy link
Contributor

@pe2mbs Can you try this?

[distutils]
index-servers:
    pypi
    forwarder

[pypi]
username: __token__
password: YOUR_ACCOUNT_TOKEN

[forwarder]
repository: https://upload.pypi.org/legacy/
username: __token__
password: YOUR_PROJECT_TOKEN

I think this should work now:

$ twine upload --repository forwarder ./dist/*

@pe2mbs
Copy link
Author

pe2mbs commented Jan 27, 2020

@bhrutledge the info provided above gives the following error.

InvalidConfiguration: Missing 'forwarder' section from the configuration file
or not a complete URL in --repository-url.
Maybe you have a out-dated '~/.pypirc' format?
more info: https://docs.python.org/distutils/packageindex.html#pypirc

@bhrutledge bhrutledge added the support Users asking for help using twine label Feb 1, 2020
@bhrutledge
Copy link
Contributor

@pe2mbs I'm surprised to see that error. I copied and pasted my suggested contents into a new file, and got this result:

$ twine upload --config-file .pypirc --repository forwarder dist/*
...
HTTPError: 403 Client Error: Invalid or non-existent authentication information. for url: https://upload.pypi.org/legacy/

Which is what I would expect, because I didn't change YOUR_PROJECT_TOKEN. I can reproduce the error you received by removing forwarder from the list of index-servers.

Are you sure that you're using the correct .pypirc, and that it matches my suggestion? By default, twine will use $HOME/.pypirc. It might be helpful if you copy & paste the following:

  • The complete contents of the .pypirc that you're using (with your tokens obscured, of course)
  • The complete twine upload command that you used
  • The complete output of the twine upload command

@bhrutledge
Copy link
Contributor

Since we haven't heard from @pe2mbs in awhile, and in light of my last comment, I'm going to close this. If folks are still getting this error, feel free to post comments, and we can re-open if necessary.

@angerson
Copy link

angerson commented Jun 17, 2021

I ran into something similar when using --config-file=/path/to/file. I typoed a non-existent path and got

InvalidConfiguration: Missing 'test-warehouse' section from the configuration file
or not a complete URL in --repository-url.
Maybe you have an out-dated '/path/to/missing/file' format?
more info: https://packaging.python.org/specifications/pypirc/

So I mistakenly thought the file was there with an outdated format (I have twine 3.4.1).

A nice change would be if a non-existent config file path raised a different error instead:

InvalidConfigFilePath: The configuration file '/path/to/missing/file' does not
exist or is not readable. Please check that the file exists and that
it has read permissions for your user.

@bhrutledge
Copy link
Contributor

Ah, thanks @angerson. Here's a complete reproducing command example:

% twine upload --config-file /path/to/missing/file --repository undefined-repository dist/*
InvalidConfiguration: Missing 'undefined-repository' section from the configuration file
or not a complete URL in --repository-url.
Maybe you have an out-dated '/path/to/missing/file' format?
more info: https://packaging.python.org/specifications/pypirc/

I agree that something like what the error message proposed would be better.

Interestingly, if you omit the --repository option (i.e. use the default of PyPI), Twine seems to silently ignore the missing config file:

% twine upload --config-file /path/to/missing/file  dist/*                                 
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: 

In this case, I think Twine should show a warning, but continue with the current behavior of manually entering credentials.

With that in mind, I'm happy to reopen this.

@bhrutledge bhrutledge reopened this Jun 18, 2021
@bhrutledge bhrutledge added enhancement and removed support Users asking for help using twine labels Jun 18, 2021
@bhrutledge bhrutledge changed the title .pypirc doesn't work as expected Confusing error messages with missing config file Jun 18, 2021
@bhrutledge
Copy link
Contributor

I'm working on this, and taking the opportunity to clarify/simplify the config file logic and tests.

Work-in-progress: main...bhrutledge:564-config-file

@bhrutledge
Copy link
Contributor

Released in https://pypi.org/project/twine/3.4.2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants