Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion wagtailio/packages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
from .models import Grid, Package


headers = {
"Accept": "application/json",
"User-Agent": "Wagtail.org Packages Importer",
}


Comment on lines +12 to +17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no need of the headers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @p-r-a-v-i-n, the goal was to seem less suspicious to Cloudflare by not using the default User-Agent header set by requests.

This did not work, so I might change this to the header of a browser to see if that works instead.

def process(url="https://djangopackages.org/api/v4/grids/?q=wagtail"):
grid_data = requests.get(url).json() # noqa: S113
response = requests.get(url, headers=headers, timeout=10)
if not response.ok:
raise ValueError(f"Failed to fetch data from {url}: {response.status_code}")

grid_data = response.json()
Comment on lines +19 to +23
Copy link
Copy Markdown
Contributor

@p-r-a-v-i-n p-r-a-v-i-n Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! but just opinon here:
what do you think of using try-except block here to raise error, bcs sometimes requests won't even allow to perform request.ok if respective server is down.

for item in grid_data.get("results", []):
title = item.get("title", "")
if "wagtail" in title.lower():
Expand Down