Skip to content

Fix HTTP 429 from pypistats.org by adding User-Agent header#5

Draft
ragonneau with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-fetch-download-statistics
Draft

Fix HTTP 429 from pypistats.org by adding User-Agent header#5
ragonneau with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-fetch-download-statistics

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown

The fetch.py script was failing with HTTP Error 429: Too Many Requests when querying the pypistats.org API, because urllib sends no meaningful User-Agent by default and pypistats.org rate-limits such requests.

Changes

  • fetch.py: Replace bare urlopen(url) in count_pypi() with a Request object that includes a User-Agent header.
# Before
pypi_api = urlopen(f"https://pypistats.org/api/packages/{package}/overall")

# After
req = Request(
    f"https://pypistats.org/api/packages/{package}/overall",
    headers={"User-Agent": "fetch-download-stats/1.0"},
)
pypi_api = urlopen(req)

Copilot AI changed the title [WIP] Fix failing GitHub Actions job Fetch the download statistics Fix HTTP 429 from pypistats.org by adding User-Agent header Jun 27, 2026
Copilot AI requested a review from ragonneau June 27, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants