fix(maizone): 兼容新版QQ空间动态接口返回的JSON格式
QQ空间监控好友动态的接口返回格式从 JSONP (_Callback(...)) 变更为纯 JSON。 本次提交通过增加判断,兼容了新旧两种数据格式,并修复了因此导致的动态拉取失败问题。 同时,为 `images` 循环中的未使用变量 `img_bytes` 添加下划线前缀,并为 `pic_bos` 和 `richvals` 两个未使用的变量添加 `# noqa: F841` 以消除 linter 警告。
This commit is contained in:
@@ -283,11 +283,11 @@ class QZoneService:
|
||||
"qzreferrer": f"https://user.qzone.qq.com/{uin}",
|
||||
}
|
||||
if images:
|
||||
pic_bos, richvals = [], []
|
||||
pic_bos, richvals = [], [] # noqa: F841
|
||||
# The original logic for uploading images is complex and involves multiple steps.
|
||||
# This simplified version captures the essence. A full implementation would require
|
||||
# a separate, robust image upload function.
|
||||
for img_bytes in images:
|
||||
for _img_bytes in images:
|
||||
# This is a placeholder for the actual image upload logic which is quite complex.
|
||||
# In a real scenario, you would call a dedicated `_upload_image` method here.
|
||||
# For now, we assume the upload is successful and we get back dummy data.
|
||||
@@ -439,12 +439,19 @@ class QZoneService:
|
||||
res_text = await _request("GET", self.ZONE_LIST_URL, params=params)
|
||||
|
||||
# 增加对返回内容的校验
|
||||
if not res_text.startswith("_Callback(") or not res_text.endswith(");"):
|
||||
if res_text.startswith("_Callback("):
|
||||
# 兼容旧版jsonp格式
|
||||
json_str = res_text[len("_Callback(") : -2]
|
||||
else:
|
||||
# 兼容新版纯json格式
|
||||
json_str = res_text
|
||||
|
||||
try:
|
||||
# 替换 undefined 为 null
|
||||
json_data = json5.loads(json_str.replace("undefined", "null"))
|
||||
except Exception:
|
||||
logger.warning(f"监控好友动态返回格式异常: {res_text}")
|
||||
return []
|
||||
|
||||
json_str = res_text[len("_Callback(") : -2].replace("undefined", "null")
|
||||
json_data = json5.loads(json_str)
|
||||
feeds_data = []
|
||||
if isinstance(json_data, dict):
|
||||
data_level1 = json_data.get("data")
|
||||
|
||||
Reference in New Issue
Block a user