fix(newsletter): use follow_redirects=False to avoid false positive on 404 redirect
Beehiiv redirects non-existent newsletters to /?404=... with HTTP 302. With follow_redirects=True, the final 200 was misread as "newsletter exists". Fix: disable redirect following so only a direct HTTP 200 = newsletter real. Also reset state back to last_sent=13 (real). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1 @@
|
|||||||
{
|
{"last_sent": 13, "year": 2026, "last_sent_at": "2026-04-02T18:18:46.000000+00:00"}
|
||||||
"last_sent": 13,
|
|
||||||
"year": 2026,
|
|
||||||
"last_sent_at": "2026-04-02T18:59:37.878273+00:00"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -35,10 +35,14 @@ def _write_state(state: dict) -> None:
|
|||||||
|
|
||||||
|
|
||||||
async def _newsletter_exists(n: int, year: int) -> bool:
|
async def _newsletter_exists(n: int, year: int) -> bool:
|
||||||
"""Return True if newsletter #{n}/{year} returns HTTP 200."""
|
"""Return True if newsletter #{n}/{year} exists (HTTP 200, no redirect to 404 page).
|
||||||
|
|
||||||
|
Beehiiv redirects non-existent newsletters: /p/newsletter-N-din-YEAR → /?404=... (302)
|
||||||
|
A real newsletter returns 200 directly without redirect.
|
||||||
|
"""
|
||||||
url = NEWSLETTER_BASE_URL.format(n=n, year=year)
|
url = NEWSLETTER_BASE_URL.format(n=n, year=year)
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(follow_redirects=True) as client:
|
async with httpx.AsyncClient(follow_redirects=False) as client:
|
||||||
resp = await client.get(url, timeout=10)
|
resp = await client.get(url, timeout=10)
|
||||||
return resp.status_code == 200
|
return resp.status_code == 200
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user