Dev qing #14
+2
-4
@@ -86,10 +86,8 @@ def review_content(content: str, timeout: int = 10) -> Dict[str, Any]:
|
|||||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
resp_data = resp.read().decode("utf-8")
|
resp_data = resp.read().decode("utf-8")
|
||||||
data = json.loads(resp_data)
|
data = json.loads(resp_data)
|
||||||
invalid: bool = data['invalid']
|
# 兼容布尔/字符串两种返回类型:仅明确判定安全才放行,其余一律拦截(fail-closed)
|
||||||
return invalid == False
|
return data.get('invalid') in (False, 'false')
|
||||||
#invalid = data
|
|
||||||
#return invalid
|
|
||||||
|
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
||||||
|
|||||||
Reference in new issue
Block a user