Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:使用Python将Json插入Postgresql时_Python_Json_Postgresql - Fatal编程技术网

错误:使用Python将Json插入Postgresql时

错误:使用Python将Json插入Postgresql时,python,json,postgresql,Python,Json,Postgresql,我正在尝试向表中插入一些值。因为我对Python和PostgreSQL非常陌生,所以我遇到了许多不同的错误。这就是为什么我会首先展示我所拥有的 我的桌子: CREATE TABLE public.vuln ( "ID" integer NOT NULL, pde json, "pde_ID" text COLLATE pg_catalog."default" NOT NULL, pde_published boolean, pde_references j

我正在尝试向表中插入一些值。因为我对Python和PostgreSQL非常陌生,所以我遇到了许多不同的错误。这就是为什么我会首先展示我所拥有的

我的桌子:

CREATE TABLE public.vuln
(
    "ID" integer NOT NULL,
    pde json,
    "pde_ID" text COLLATE pg_catalog."default" NOT NULL,
    pde_published boolean,
    pde_references json[],
    pde_description json,
    pde_impact json,
    pde_cwe text COLLATE pg_catalog."default",
    pde_valid boolean,
    pde_published_date date,
    pde_eval_has boolean,
    pde_products_has_inc_excl boolean,
    pde_products json[],
    CONSTRAINT vuln_pkey PRIMARY KEY ("ID")
)
我的插入查询:

  for vul_item in myList:
        query = """INSERT INTO vuln (pde, "pde_ID", pde_description, pde_published, pde_published_date, pde_valid, pde_cwe, 
        pde_references, pde_products, pde_eval_has_exploit, pde_vulnerable_products_has_inc_excl, pde_impact) 
        VALUES (%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s);"""
        data = (vul_item.pde, vul_item.pde_ID, vul_item.pde_description, vul_item.pde_published,
                vul_item.pde_published_date, vul_item.pde_valid, vul_item.pde_cwe, vul_item.pde_references,
                vul_item.pde_products, vul_item.pde_eval_has_exploit,
                vul_item.pde_products_has_inc_excl, vul_item.pde_impact)
        print(data)
        cr.execute(query, data)
        cr.commit()
我发现以下错误:

psycopg2.errors.InvalidTextRepresentation: ERROR:  invalid input syntax for type json
LINE 3: ...and a lot of other things."}]}}', 'PDE-201-2930', 'The....
                                                             ^
DETAIL:  Token "The" is invalid.
CONTEXT:  JSON-Daten, Zeile 1: the...
我的Python代码中Json变量的类型为:

因为我使用
json.dumps()
将它们(dict变量)转换为json。我还验证了我的Json项,它们没有语法错误

这是vul_item.pde Json:

{"data_type": "PDE", "data_format": "MITRE", "data_version": "4.0", "PDE_data_meta": {"ID": "PDE-0001", "ASSIGNER": "PDE@pde.org"}, "problemtype": {"problemtype_data": [{"description": [{"lang": "en", "value": "PWE-200"}]}]}, "references": {"reference_data": [{"url": "http://ccc.com", "name": "200110 More information regarding ", "refsource": "VULNWATCH", "tags": []}, {"url": "http://ccc.com", "name": "20030110 More information regarding Etherleak", "refsource": "BUGTRAQ", "tags": []}, {"url": "http://ccc.com", "name": "7996", "refsource": "SECUNIA", "tags": []}, {"url": "http://www.ccc.com", "name": "A010603-1", "refsource": "ATSTAKE", "tags": ["Vendor Advisory"]}, {"url": "http://www.ccc.com", "name": "http://www.ccc.com", "refsource": "MISC", "tags": []}, {"url": "http://ccc.com", "name": "VU#412115", "refsource": "CERT-VN", "tags": ["Third Party Advisory", "Resource"]}, {"url": "http://ccc.com", "name": "http://ccc.com", "refsource": "CONFIRM", "tags": []}, {"url": "http://www.osvdb.org/9962", "name": "9962", "refsource": "OSVDB", "tags": []}, {"url": "http://ccc.com", "name": "RHSA-2003:025", "refsource": "REDHAT", "tags": []}, {"url": "http://www.ccc.com", "name": "RHSA-2003:088", "refsource": "REDHAT", "tags": []}, {"url": "http://www.ccc.com", "name": "no info here", "refsource": "BUGTRAQ", "tags": []}, {"url": "http://www.ccc.com", "name": "20030117 Re: More information regarding Etherleak", "refsource": "BUsRAQ", "tags": []}, {"url": "http://www.ccc.com", "name": "1031583", "refsource": "SECssRACK", "tags": []}, {"url": "http://ccc.com", "name": "104185", "refsource": "SECTRACK", "tags": []}, {"url": "https://ccc.com", "name": "oval:org.mitre.oval:def:2665", "refsource": "OVAL", "tags": []}]}, "description": {"description_data": [{"lang": "en", "value": "The description of this product is not published."}]}}

当我尝试将这个json插入到表中时,我得到了相同的错误。

它似乎在抱怨“ip_输入”不是有效的json,这是真的。请提供vul_项目的内容,以便人们更容易帮助您。理想情况下,提供可运行的代码。我更改了它,谢谢。由于vul_item.pde不包含“ip_输入”,它可能与您收到的错误无关。我建议发布vul_项目的全部内容。我再次更改了它。在本例中,我得到的“Token”是“not found”。它实际上不是一个Token,它包含一个字符串。vul_item的内容与vul_item.pde完全相同。当我也插入vul_item.pde时,我得到了相同的错误。我通过json.dumps()转换的变量你认为这就是原因吗?它似乎在抱怨“ip_输入”不是有效的JSON,这是真的。请提供vul_项的内容,以便人们更容易帮助你。理想情况下提供可运行的代码。我更改了它,谢谢。因为vul_项.pde不包含“ip_输入”“,这可能与您遇到的错误无关。我建议发布vul_项目的全部内容。我再次更改了它。在本例中,我得到的“Token”是“not found”。它实际上不是一个Token,它包含一个字符串。vul_item的内容与vul_item.pde完全相同。当我刚刚插入vul_item.pde时,我得到了相同的错误。我用json.dumps()转换的变量是dict。你认为这是原因吗?