How to troubleshoot PyPi issues

Subject 

Comparing correct PyPi REST API calls can show where the problem lies.

Affected Versions

4.0.2 – Latest

Description

When troubleshooting PyPi errors it is best to compare what is supposed to happen against what is currently happening. You can eliminate a great deal of noise by simulating each step the client takes, and examining what HTTP return code is sent by Artifactory.

In general, these return codes indicate where to look next:
403 and 401 – Authentication issue, examine authorization settings
404 – Resource not found, check repository for resource
400 – Incorrect request, use curl to get reason phrase
50X – Server problem, examine artifactory.log

Resolution

Using curl
The libcurl terminal application can make basic REST API commands such as GET or PUT options. The Artifactory request logs display the exact API commands the Docker client uses.

You can use the examples below, or substitute the one that is failing in the Artifactory request.log file. Doing so should yield further information on the problem, and possible next steps.

Basic usage (with #comments):

curl -uadmin #Artifactory-username -vvv #verbosy -k #ignore-insecure-SSL -XGET #GET-request http://localhost:8081/artifactory/api/system/ping
 

Curl uses GET requests by default. Other commands like "PUT" require the –data field, along with the (Usually JSON) data payload. An example PUT command:

curl -uadmin:password -XPUT -H"Content-type: Application/json" –data '{"name":"test-group"}' http://localhost:8081/artifactory/api/security/groups/test-group

pip install
When a user installs a package using the Pip client, they make use of the PyPi REST API to download the package. The pip client does a few actions when attempting to install a package through Artifactory. The process begins when a user enters the following command:
pip install nginxctl

The client first pulls the metadata from the “/simple” API endpoint:

20180524093654|538|REQUEST|127.0.0.1|anonymous|GET|/api/pypi/pypi/simple/nginxctl/|HTTP/1.1|200|0

Using this metadata, it downloads the .tar.gz file:

20180524093656|1412|REQUEST|127.0.0.1|anonymous|GET|/api/pypi/pypi/packages/72/45/936e0805da71fcaf0e5a1f9256f757f5fa95057e391687ba067ef2d52926/nginxctl-1.1.2.tar.gz|HTTP/1.1|200|17024

The client then installs the package from the downloaded .tar.gz.

Deploying Packages:
When you have configured the package’s .pypirc to point to Artifactory, you can then run the following command to initiate the deployment:

python setup.py sdist upload -r local
—or—
python setup.py bdist_wheel upload -r local

This performs a POST action that submits the package to Artifactory:

20180524094126|10499|REQUEST|127.0.0.1|admin|POST|/api/pypi/pypi|HTTP/1.1|200|3357

Depending on if you specified a Python Wheel or a simple package upload, you will see the deployed file in your PyPi local repository:

Example PyPi package

/simple
In Artifactory PyPi package metadata is available under “/api/pypi/<PyPi_Repo>/simple/”. You can inspect this URL in your web browser to see if there is a problem getting the PyPi package metadata:
Deployed PyPi package