Get {"error":"404 Not Found"} when uploading pypi package to gitlab with twine

1.8k Views Asked by At

I am following the official documentation while trying to upload my pypi package to gitlab private repository using twine.

I am working on a community project on gitlab.com that is set to private.

I am using the following commandline:

twine upload dist/*.tar.gz --skip-existing --verbose --repository-url https://gitlab.com/api/v4/projects/mygroup/myproject/packages/pypi

When I run this command, twine asks for username and password. I enter my email and 2-factor token (I have 2-factor authentication enabled for my gitlab.com account)

Enter your username: [email protected]
/home/myname/.venv/myproject/lib/python3.7/site-packages/twine/auth.py:72: UserWarning: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details.
  warnings.warn(str(exc))

Enter your password: 

Then I get a pleasant message:

Uploading myproject-0.0.1.tar.gz
100%|██████████████████| 25.6k/25.6k [00:00<00:00, 87.4kB/s]

Followed by a less pleasant error message:

Content received from server:
{"error":"404 Not Found"}
HTTPError: 404 Not Found from https://gitlab.com/api/v4/projects/mygroup/myproject/packages/pypi
Not Found

At this stage I have a few comments.

  1. Documentation mentions a repository of example gitlab-ci.yaml files but there is no mention of PyPi or twine in in any of the examples that I could find there.

  2. Documentation mentions gitlab.example.com. I don't know why, will this work for gitlab.com as well?

Anyway, I don't know how to proceed from here. I have limited ways of debugging this or interpreting the meaning of the resulting error. How can I make this work?

2

There are 2 best solutions below

0
On

As far as I know, you have to use the project id in the repository-url:

twine upload dist/*.tar.gz --skip-existing --verbose --repository-url https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi
0
On

If it is part of CI then better use gitlab variables:

twine upload dist/*.tar.gz --skip-existing --verbose --repository-url 
 ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi

This will properly take package_id and api url