Percent-encode the all-clear image URL (#152) #153
No reviewers
Labels
No labels
area:ai
area:ci-cd
area:notifications
area:observability
area:public-pages
backlog
bug
duplicate
enhancement
help wanted
invalid
question
type:decision
type:feature
type:infra
type:maintenance
type:security
v1.0.1
v1.1.0
v1.2.0
v1.3.0
v2.0.0
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/WeatherBot!153
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/allclear-image-url-space"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #152. Root cause of the Webex HTTP 400 loop reported in #148 — that issue fixed the unbounded retry; this fixes the rejection.
Diagnosis
Iowa State's
validpath segment is'YYYY-MM-DD HHMM'— it contains a space._iastate_allclear_image_urlembedded it raw, producing a URL that is not a valid URI:That string is handed to Webex as a
files[]URL. Webex validates it, finds it malformed, and rejects the entire message with HTTP 400.Confirmed empirically:
Why this was hard to spot
Three things hid it:
_iastate_alert_image_urlbuilds the same URL without thevalid:segment, so it has no space. That asymmetry — alerts fine, all-clears failing — is what identified the cause.radar.fetch_iastate_warning_imageuses the same helper but passes the string to httpx, which percent-encodes it. Only URLs handed verbatim to a third party break.Other consumers
The same malformed URL also reaches
webhook.py:647/:671(Discord embed and webhook payloads) andapp/api/public.py:185(public alert page). Those fail less visibly — browsers percent-encode asrcautomatically — but the URL is malformed regardless, so fixing it at the source repairs all of them.Fix
quote(..., safe="")on the valid value, at the point of use. Deliberately not inside_format_iastate_valid: that helper is documented as returning the human-readable format and the fetch path relies on httpx encoding it, so encoding there would risk double-encoding.Tests
tests/test_iastate_image_urls.py— no raw space,%20present, segment separators and.pngsuffix intact, URL parses as a proper URI with no whitespace anywhere, plus a control that the alert variant is unchanged and still has novalid:segment, and the twoNoneguards.Verification
ruff check .python -m compileall app000→ encoded200 image/png🤖 Generated with Claude Code