Not able to upload package in https://upload.pypi.org/legacy/ - python

I have gone through already available answers in SO but nothing seems working for me.
I am following python commands to upload my package(Note: I am a new user and have registered the account with username and password):
Create setup.py:
from setuptools import setup
setup(
name='', # This is the name of your PyPI-package.
version='0.1', # Update the version number for new releases
scripts=[''] # The name of your script, and also the command you'll be using for calling it
)
Package the script:
python setup.py sdist
Register the account:
python setup.py register
This prompted me below message(I choose 2nd as I am new user):
1. use your existing login,
2. register as a new user,
3. have the server generate a new password for you (and email it to you), or
4. quit
Your selection [default 1]:
Upload the package:
python setup.py sdist upload
After trying steps I got the error while uploading:
Upload failed (403): Invalid or non-existent authentication information.
error: Upload failed (403): Invalid or non-existent authentication information.

After a lot of trial and error, I found the simple solution. Also, #hoefling answer helps me to solve them.
Register as a user in https://pypi.org/ and use register account command which mentioned in the question.
Now, Three magic steps which will resolve the issue.
pip install twine
python setup.py sdist
# This will ask for you username and password
twine upload dist/*
EDIT:
If you want to upgrade your package, just follow the below simple steps:
Delete the build, dist, and <package name>.egg-info folders in your root directory.
Change the version number in your setup.py file.
Create distribution again. e.g: python setup.py sdist bdist_wheel
Upload distribution again. e.g: twine upload dist/*

First of all, note that register is deprecated and not necessary anymore. When trying to register a package on PyPI, you should get a message:
Server response (410): This API is no longer supported, instead simply upload the file.
Just skip the register step and proceed with the uploading.
distutils/setuptools
Create a file $HOME/.pypirc with the contents:
[distutils]
index-servers =
pypi
[pypi]
username: <username>
password: <password>
and repeat the upload:
$ python setup.py sdist upload
Thing is, the distutils' upload subcommand doesn't provide an option to enter the credentials from command line, instead completely relying on the .pypirc file.
twine
If storing credentials in plain text format is not your thing, twine provides a possibility of entering credentials from command line. This is also the officially recommended tool for uploading packages.
Install twine:
$ pip install twine
Build the package:
$ python setup.py clean sdist
Upload:
$ twine upload dist/*
The tool will ask you for the username and password.
twine also lets you provide the credentials in environment variables:
$ TWINE_USERNAME=me TWINE_PASSWORD=passwd twine upload dist/*
or via keyring.

Create a file in home dir by touch ~/.pypirc similar look like: added pytest optionally
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository=https://pypi.python.org/pypi
username=your_username
password=your_password
[pypitest]
repository=https://testpypi.python.org/pypi
username=your_username
password=your_password
Things to care about the following error
403: Invalid or non-existent authentication information
If there is a % in your password just type it without escaping; e.g. Hello%123
If there is a space character in your password just type it without quotes; e.g. Hello 123
Register your package against PyPI's server
python setup.py register -r pypi
Upload your package
python setup.py sdist upload -r pypi
From official doc
First, you need a PyPI user account

To change to the new PyPI authentication method, go to https://pypi.org/manage/account/token/
Login to your account and you'll see
Give the token a name, select the Scope (i.e. what repository do you allow the Token to be used for).
Then copy the token as the password in your ~/.pypirc file, use __token__ as the username, e.g.
[distutils]
index-servers =
pypi
testpypi
[pypi]
username: __token__
password: pypi-12837192048i1234...

Related

Python Package publish in Azure DevOps Artifacts: 'D:\a\1\a' is empty. Nothing will be added to build artifact

A. Used twine to authenticate and publish my Python packages to an Azure Artifacts feed
- task: CmdLine#2
displayName: Build Artifacts
inputs:
script:
echo Building distribution package
python -m pip install --upgrade twine build setuptools
python -m build
- task: TwineAuthenticate#1
inputs:
artifactFeed: ddey-feed
- script:
python -m twine upload -r "ddey-feed" --config-file $(PYPIRC_PATH) dist/*.whl
B. Although it ran successfully, but I didn't get any package in Artifacts. I found the Warning:'D:\a\1\a' is empty. Nothing will be added to build artifact
C. I did some research and decided to add additional section which does a copy and publish
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*
!.git/**/*
TargetFolder: '$(Build.ArtifactStagingDirectory)'
condition: succeededOrFailed()
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Can anyone please comment what else I can modify in yaml file to get the package available in Artifacts?
Different Tried things after Suggestions:
Add Tree command to see all build folders to confirm generation of file:
2. After removing source folder and let it use default source
successful build and consumed:
Artifacts is generated and I can see it from pipeline.
Problem Statement
In Artifacts tab, I don't see the build available in any feed. How to connect the build with a specific feed (ddey-feed). I though TwineAuthenticate is suppose to take care of it.
ok. I have finally resolved the whole issue and could deploy the package to Artifacts Feed.
Key learning:
When creating Artifacts Feed, Make sure to check permission. Add Allow project-scoped builds otherwise will get permission error in pushing package from Azure pipeline
You need to define PYPIRC_PATH to point where .pypirc file reside. This can be done using environment variable set-up as shown below
- script: |
echo "$(PYPIRC_PATH)"
python -m twine upload -r ddey-feed --verbose --config-file $(PYPIRC_PATH) dist/*
displayName: 'cmd to push package to Artifact Feed'
env:
PYPIRC_PATH: $(Build.SourcesDirectory)
Make sure Twine Authenticate feed name matches with twine upload feed name. If pipeline fails to push the package, you can try to run following command directly from your repo: twine upload -r ddey-feed --config-file ./.pypirc dist/ and it should successfully upload the build to Artifacts.
For debug purpose, print the directories.
echo "Structure of work folder of this pipeline:"
tree $(Agent.WorkFolder)\1 /f
echo "Build.ArtifactStagingDirectory:"
echo "$(Build.ArtifactStagingDirectory)"
echo "Build.BinariesDirectory:"
echo "$(Build.BinariesDirectory)"
echo "Build.SourcesDirectory:"
echo "$(Build.SourcesDirectory)"
Summary of components of the pipeline
Indentation before CopyFiles#2

403 Client Error: Invalid or non-existent authentication information while uploading to Pypi with twine

403 Client Error: Invalid or non-existent authentication information occurs when uploading new module to pypi with Twine
Win10 Pro 1803 Biuld 17134.1069 64 bit // Python 3.7.5 32 bit // pip 19.3.1
I successfully created tar. and whl. in the dist folder, registered on https://pypi.org/ with e-mail confirmation and started to upload.
I checked both files with command line ('PASSED')
and did the following:
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: gakonorde
Enter your password:
Uploading gersyll-Alpha.release-py3-none-any.whl
100%|█████████████████████████████████████████████████████████████████████████████| 6.43k/6.43k [00:01<00:00, 5.12kB/s]
NOTE: Try --verbose to see response content.
HTTPError: 403 Client Error: Invalid or non-existent authentication information. for url: https://upload.pypi.org/legacy/
The command line does not allow me to enter password after username. I only can press ENTER.
I tried also
Password for 'your-username' in 'https://upload.pypi.org/legacy/':
... and again, I can press nothing except of ENTER.
Then I created .pypirc file with credentials for https://pypi.org/ and its test version and run python -m twine upload dist/* again
I was not asked for a password, but got the same error:
Uploading distributions to https://upload.pypi.org/legacy/
Uploading gersyll-Alpha.release-py3-none-any.whl
100%|█████████████████████████████████████████████████████████████████████████████| 6.43k/6.43k [00:01<00:00, 5.46kB/s]
NOTE: Try --verbose to see response content.
HTTPError: 403 Client Error: Invalid or non-existent authentication information. for url: https://upload.pypi.org/legacy/
When I combine .pypirc with API token, the problem remains the same.
I can enter my account on https://pypi.org/, so it obviously exists (and e-mail is verified).
I also added the second e-mail, verified and set it as primary (nothing changed).
Here is my setup.py:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="gersyll",
version="Alpha release",
author="gakonorde",
author_email="gabrielko#yandex.ru",
description="This module counts the number of words of different syllable length for all texts in a directory",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/gakonorde/gersyll",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3.7",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.7',
)
What am I doing wrong?
Any help would be greatly appreciated.
Edit:
The .pypirc file is in the same folder as .setup, README, License, dict/ etc.
It's content is as follows:
[distutils]
index-servers =
pypi
pypitest
[pypitest]
repository: testpypi.python.org/pypi
username: gakonorde
password: [my_password]
[pypi]
repository: upload.pypi.org/legacy
username: gakonorde
password: [my_password]
Solved with
python -m twine upload -u USERNAME -p PASSWORD dist/*
With regards to the password prompt, you won't see any input after the Enter your password: prompt, because it's hiding your password.
For your .pypirc file, this should be in your home directory (~/.pypirc), not in the same directory as your setup.py file.

My home does not have .pypirc file which is giving me an error while registering the python package to PyPI

I am using ubuntu and I have created a python package and it is ready to register on PyPI but when I use python setup.py register it is showing an error like this:
Server response (410): This API is no longer supported, instead simply upload the file.
I know that this is the error of not finding the .pypirc file but I don't know how to fix this because my home does not have the .pypirc file.Can't we just create the pypirc file?(just asking). Also there is a different error when I use the register command in the virtualenv, I get this:
Server response (410): Gone (This API has been deprecated and removed from legacy PyPI in favor of using the APIs available in the new PyPI.org implementation of PyPI (located at https://pypi.org/). For more information about migrating your use of this API to PyPI.org, please see https://packaging.python.org/guides/migrating-to-pypi-org/#uploading. For more information about the sunsetting of this API, please see https://mail.python.org/pipermail/distutils-sig/2017-June/030766.html)
and here is my setup.py file
from setuptools import setup
setup(name='Utilitarian',
version='0.1',
description='little description',
url='https://github.com/Shivams334/Utilitarian.git',
author='Shivam Sharma',
author_email='shivams334#gmail.com',
license='MIT',
packages=['Utilitarian'],
zip_safe=False)
Please help. Thank you.
You need to create .pypirc file by yourself in your HOME directory
touch ~/.pypirc
this file should contain the following code, put you login and password from pypi
[distutils]
index-servers =
pypi
pypitest
[pypitest]
repository = https://test.pypi.org/legacy/
username = <your username>
password = <your password>
[pypi]
repository = https://upload.pypi.org/legacy/
username = <your username>
password = <your password>
Because you put you login and password into this file, you may want to change it's permission so that only you can read and write it.
chmod 600 ~/.pypirc
And after it you can try to register your package, by the way I hightly recommend you using twine library to load your package, just install it
pip install twine
Then make a distribution for your package
python setup.py install
This command will create a dist folder with your module packed inside then register your project (if necessary):
twine register dist/example-project-x.y.z.tar.gz
after it you can upload your package to pip with the following command
twine upload dist/*

How to not store password in .pypirc?

I'm trying to set up a private Pypi cloud using CloudPypi. And I really don't want store my password in .pypirc. I want to be prompt to type in my password every time I upload a package.
In Python document about .pypirc, it says:
password, that will be used to authenticate. If omitted the user will
be prompt to type it when needed.
But how do you "omit" the password here? I tried leaving the password line blank, tried do "password : " or "password : password". None of these works.
You omit the entire line completely:
[distutils]
index-servers =
pypi
[pypi]
repository: <repository-url>
username: <username>
This has been tested on Python 3.6.2 and pip 9.0.1
Omitting password: in .pypirc is broken since setuptools 42.0.2 (Dec 2019), and will not be fixed (see https://github.com/pypa/setuptools/issues/2006 ).
Instead, you should use twine to upload packages. It will prompt for the password if omitted from .pypirc . See https://twine.readthedocs.io
Example:
pip install twine
twine upload -r mypypi dist/* --verbose

How do you upload your module to Python testing site at https://testpypi.python.org/pypi on a Windows 7 computer?

My tools:
Windows 7 ,
Python 3.4.2
I am going through Chapter 2 of Head First Python by Paul Barry Nov 2010 .
Part of the requirements is to upload my distribution to PyPI testing site.
Unfortunately I haven't been successful.
All the reading I have done so far say that I need to make use of this HOME environment variable in Windows, or put .pypirc in the home directory of Windows 7.
Well, there is no such environment variable in Windows 7, nor such directory.
..........Can somebody please give me a step by step guide using the command line tool in Windows 7?
So far, I have created a .pypirc.txt file in this directory C:\Python34\nesterhead , where my module is residing in Windows 7.
I then used the command line tool to rename the .txt file from .pypirc.txt to .pypirc. , i.e.
cd C:\Python34\nesterhead
REN .pypirc.txt .pypirc.
c:\python34\python.exe setup.py register -r pypitest
..........And I got this as the output.
ValueError: pypitest not found in .pypirc
..........I have done all the things I am supposed to do , including confirming my registration and checking "I agree' with https://testpypi.python.org/pypi
..........I have also followed the instructions from http://peterdowns.com/posts/first-time-with-pypi.html and have the following code with the correct usernames and passwords in my .pypirc.txt
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository: https://pypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}
[pypitest]
repository: https://testpypi.python.org/pypi
username: {{your_username}}
password: {{your_password}}
Thank you very much.
echo %userprofile%
This will display your home directory in windows 7

Categories

Resources