v0.6.3: encode-safe URLs to Seerr (fixes #4)
Queries containing apostrophes/parens/etc were 400ing on Seerr's strict ajv validator. The SeerrClient _qs() helper percent-encodes the value correctly, but aiohttp parses the URL string through yarl.URL(), which normalizes %27 (and other sub-delims) back to the literal character in the query component. The literal ' then trips Seerr's "must be url encoded" check. Fix: pass yarl.URL(url, encoded=True) to bypass yarl's re-normalization so the RFC 3986 form built by _qs reaches Seerr unchanged. Reproduced + verified against deployed Seerr v3.2.0 with queries including "rocky's revenge", "what's up, doc?", "8 1/2". Closes #4
This commit is contained in:
parent
87eef44d93
commit
2be3d22306
2 changed files with 6 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.3.1
|
maubot: 0.3.1
|
||||||
id: com.3ddbrewery.media
|
id: com.3ddbrewery.media
|
||||||
version: 0.6.2
|
version: 0.6.3
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- media_bot
|
- media_bot
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from typing import Optional
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import yarl
|
||||||
|
|
||||||
|
|
||||||
class SeerrError(RuntimeError):
|
class SeerrError(RuntimeError):
|
||||||
|
|
@ -34,7 +35,10 @@ class SeerrClient:
|
||||||
url = f"{self.base}{path}"
|
url = f"{self.base}{path}"
|
||||||
if params:
|
if params:
|
||||||
url += "?" + _qs(params)
|
url += "?" + _qs(params)
|
||||||
async with self.session.get(url, headers=self.headers) as r:
|
# yarl decodes "safe" sub-delims like %27 back to literal ' in the query,
|
||||||
|
# which Seerr's strict ajv validator then rejects. encoded=True keeps the
|
||||||
|
# RFC 3986 encoding we built with _qs intact on the wire.
|
||||||
|
async with self.session.get(yarl.URL(url, encoded=True), headers=self.headers) as r:
|
||||||
if r.status >= 400:
|
if r.status >= 400:
|
||||||
raise SeerrError(f"GET {path} → {r.status}: {(await r.text())[:200]}")
|
raise SeerrError(f"GET {path} → {r.status}: {(await r.text())[:200]}")
|
||||||
return await r.json()
|
return await r.json()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue