Mr. Developerdude
Mr. Developerdude

Reputation: 9678

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

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?

Upvotes: 1

Views: 2288

Answers (3)

Pierre.Sassoulas
Pierre.Sassoulas

Reputation: 4282

I had this error because I was using https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi/simple (which is what pip needs as extra-index and is valid in a browser), instead https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi (which is what twine needs, but fail in pip or a browser)

Upvotes: 1

Alexander Lyapin
Alexander Lyapin

Reputation: 347

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

Upvotes: 0

floek
floek

Reputation: 51

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

Upvotes: 3

Related Questions