无法序列化从 python 中的剩余 api 返回的 json 数组对象

Unable to serialize json array object returned from rest api in python

我正在休息 api 来自 google 云的 json 格式的回复

我在 python 脚本 (3.7) 中将此响应分配给字典对象 row={} 以插入到 bigquery

"upgrade": {
            "distribution": {
                "cpeUri": "cpe:/o:centos:centos:7",
                "classification": "Unknown",
                "severity": "Unknown"
                "cve": [
                    "CVE-2020-3288"
                ]
            }
        }

我像这样将它们分配给字典对象:

row["cpeUri"]=upgrade.distribution.cpeUri
row["cve"]=upgrade.distribution.cve //**This line gives me the following error:**

root        : INFO     CVE List ['CVE-2020-3288']
root        : ERROR    **Object of type Repeated is not JSON serializable**
Traceback (most recent call last):
  File "compliance_report.py", line 409, in main
    publish_bigquery(occurrenceslist,projectid,batch_id,batch_start_time)
  File "compliance_report _latest.py", line 165, in publish_bigquery
    row["cve"]=json.dumps(occurrenceresponse.upgrade.distribution.cve)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Repeated is not JSON serializable
root        : ERROR
------------------------------\Exception
  1. 如果将代码更改为

    行["cve"]=json.dumps(upgrade.distribution.cve)

我仍然遇到同样的错误。

所有其他字段都在工作。谁能提出解决方案?

以下更改对我有用:

cve_list = []

 for obj in occurrenceresponse.upgrade.distribution.cve:
   cve_list.append(obj)
 row["cve"]=cve_list

现在我没有收到序列化错误