mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-02 21:22:51 +00:00
fix(robots-check): decode curl output as UTF-8 so non-ASCII responses stop reading as UNCONFIRMED on Windows (#506)
_fetch() ran curl with text=True and no encoding, so Python decoded the response with the Windows ANSI code page. On a byte that code page leaves undefined (0x81 in cp1252 and cp1254, 0x9e in cp1254) subprocess's pipe reader thread died, stdout came back None, rpartition() raised AttributeError, and the gate printed "UNCONFIRMED (AttributeError)". That fails closed, but it blocked the browser-header retry 09-web-research.md permits on hosts such as tr.indeed.com (a UTF-8 CJK Disallow rule) and kap.org.tr (a UTF-8 Turkish 404 page). Pin encoding='utf-8', errors='replace' on the call (RFC 9309: robots.txt is UTF-8), as verify_pdf.py and verify_layout.py already do. Decision rules and the fail-closed handling of real read failures are unchanged. The regression tests swap curl for a child process that prints the real bytes, so the actual subprocess decode path runs with _fetch's own kwargs, and pin cp1254 when no encoding is passed so a UTF-8 host cannot pass the bug by luck. Both fail on master. Co-authored-by: Can Mugan <217335573+canmugan@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+75
-1
No files matched your search
@@ -37,7 +37,10 @@ def _fetch(url, ua):
|
||||
r = subprocess.run(
|
||||
['curl', '-sS', '-L', '--max-redirs', '5', '--max-time', '12', '-A', ua,
|
||||
'-H', 'Accept: text/plain,*/*', '-w', '\n%{http_code}', '--', url],
|
||||
capture_output=True, text=True, timeout=20)
|
||||
# robots.txt is UTF-8 (RFC 9309). Unpinned, Turkish Windows decoded it as
|
||||
# cp1254, where bytes like 0x81 are undefined: the pipe reader thread died,
|
||||
# stdout came back None, and tr.indeed.com read as UNCONFIRMED.
|
||||
capture_output=True, text=True, encoding='utf-8', errors='replace', timeout=20)
|
||||
if r.returncode != 0:
|
||||
raise RuntimeError('curl exit %d' % r.returncode)
|
||||
body, _, code = r.stdout.rpartition('\n')
|
||||
|
||||
Reference in new issue
Block a user