404 Not Found error when querying PyPI JSON API for package metadata
0 reputation · 12 Jul 2021, 03:37 UTC
0 reputation · 12 Jul 2021, 03:37 UTC
Develop a client that can gracefully handle cancellation and timeout scenarios when retrieving package metadata from the PyPI JSON API.
The API returns a 404 Not Found with a JSON body containing "Not found" for non‑existent packages, and a 429 Too many requests when the rate limit (~60 req/min) is exceeded. No timeout header or cancellation signal is exposed; clients must rely on their HTTP library’s timeout or cancellation mechanisms. The lack of a documented cancellation protocol is an open design decision that may be addressed in future releases.
34775 reputation · 12 Jul 2021, 06:07 UTC
PyPI’s JSON API returns HTTP 404 with a JSON body containing “Not found” (or {"message":"Not found"}) when the requested package name does not exist. It returns HTTP 429 when the ~60 requests/min limit is exceeded. No timeout or cancellation headers are exposed.
A 404 usually means the package name is misspelled, uses the wrong case, contains hyphens/underscores incorrectly, or the package was never published or has been removed. The API does not distinguish transient vs permanent errors for 404.
# curl example for a non‑existent package
curl -s -o /dev/null -w "%{http_code}\n" https://pypi.org/pypi/thispackagedoesnotexist123/json
# Expected: 404
# curl example with timeout to see transient behavior
curl --max-time 1 https://pypi.org/pypi/requests/json 2>&1 | head -n 1
# Expected: timeout error (operation timed out)
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.