如何将curl POST 转换为美国专利局API 的Python requests.post?

问题描述 投票:0回答:2

我想使用 Python requests.post() 通过 API 从美国专利商标局获取数据。 API 的详细信息显示在此处

该页面还包含一个可用于试用 API 的小部件。 在标准字段中输入适当的条目,它会生成带有curl语句的相应API,例如

curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'criteria=patentApplicationNumber%3A%20%2215931761%22&start=0&rows=100' 'https://developer.uspto.gov/ds-api/enriched_cited_reference_metadata/v2/records'

我尝试使用curl-to-Python转换器here,它产生了以下内容:

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': 'application/json',
}

data = {
    'criteria': 'patentApplicationNumber: "15931761"',
    'start': '0',
    'rows': '100',
}

response = requests.post(
    'https://developer.uspto.gov/ds-api/enriched_cited_reference_metadata/v2/records',
    headers=headers,
    data=data,
)

不幸的是,这会产生一个带有很长回溯的错误。我没有将其包含在这里,因为我认为它没有帮助,但如果需要,我可以添加它。

如果您能提供有关如何更正 requests.post() 语法以使 API 识别它的指导,我将不胜感激。

python curl python-requests
2个回答
0
投票

您的代码似乎是正确的,但添加

verify=False
(或者更好,提供正确的证书)以连接到服务器:

import requests

url = 'https://developer.uspto.gov/ds-api/enriched_cited_reference_metadata/v2/records'

data = {
    'criteria': 'patentApplicationNumber: "15931761"',
    'start': 0,
    'rows': 100
}

out = requests.post(url, data=data, verify=False).json()
print(out)

打印:

{
    "responseHeader": {
        "zkConnected": True,
        "status": 0,
        "QTime": 0,
        "params": {
            "json": '{"params":{"q":"patentApplicationNumber: \\"15931761\\"","start":0,"rows":100,"fl":"applicantCitedExaminerReferenceIndicator,citationCategoryCode,citedDocumentIdentifier,createDateTime,createUserIdentifier,examinerCitedReferenceIndicator,groupArtUnitNumber,id,inventorNameText,obsoleteDocumentIdentifier,officeActionCategory,officeActionDate,passageLocationText,patentApplicationNumber,qualitySummaryText,relatedClaimNumberText,techCenter,workGroup","wt":"json","indent":"on"}}'
        },
    },
    "response": {
        "numFound": 14,
        "start": 0,
        "docs": [
            {
                "id": "5829161452615b32ddde83914a441f63",
                "applicantCitedExaminerReferenceIndicator": True,
                "citationCategoryCode": "Y",
                "citedDocumentIdentifier": "US 20120223801 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": False,
                "inventorNameText": "Moon",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "passageLocationText": ["par. 0009 | par. 0069 | F.2d"],
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "relatedClaimNumberText": "4",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "0923fddf0c2df361530dd7e7be8e3913",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20140306795 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Kato; Motofumi",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "25e7a8360176ddd95177ebe424a89e62",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20100173509 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "HOLBROOK; MEGHAN ANN",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "1f5f19101b555590604eba29f26a2625",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "Y",
                "citedDocumentIdentifier": "US 20080191832 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Tsai; Chon-Ming",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "passageLocationText": [
                    "Fig. 4-5 | par. 0043 | par. 0045-0048 | F.2d | claim 3 | claim 5 | claim 1 | claim 7 | par. 0046 | claim 2 | claim 4 | claim 6"
                ],
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "relatedClaimNumberText": "1-7",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "671da6feb6a77837bcfbd50ae3b72dba",
                "applicantCitedExaminerReferenceIndicator": True,
                "citationCategoryCode": "Y",
                "citedDocumentIdentifier": "US 20130069001 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": False,
                "inventorNameText": "Luo et al.",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "passageLocationText": ["par. 0129, 130 | F.2d"],
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "relatedClaimNumberText": "6",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "61c801c057ff235c5d17ac7d0dc83fed",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "Y",
                "citedDocumentIdentifier": "US 4342881 A",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Fukuda; Sunichi",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "passageLocationText": [
                    "col. 2 lines 7-10 | col. 2 line 6 col. 3 line 4 | F.2d"
                ],
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "relatedClaimNumberText": "2",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "9f516d0bd44a02a659cb95e5fe7e43c4",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20190315031 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Asahi; Atsushi",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "8a3f9761f6edc6c6d590ac8598d50539",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 9831056 B2",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Mochizuki; Hirofumi",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "a937b9747f887cb36609892ff48911ea",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20070075822 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Pachla; Timothy E.",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "c0cabbd997071a8b56f5c3c39a49c87f",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20070018774 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Dietsch; Gordon T.",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "bfb1e59486c613f384ea1b9d6f9a4707",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20140356671 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Dawley; Evan J.",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "f83f64c0fd7db562362efc816d3eed92",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20100178813 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "HOLBROOK; MEGHAN ANN",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "e1ddb9c1be3db9476042f265e56b1367",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "Y",
                "citedDocumentIdentifier": "US 20030024105 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "Chiu, Tony",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "passageLocationText": [
                    "claim 1 | par. 0029 Fig. 4-7 | par. 0029 | F.2d | claim 3 | claim 5 | claim 7 | claim 2 | claim 4 | claim 6"
                ],
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "relatedClaimNumberText": "1-7",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
            {
                "id": "dd0ebf2bbf630c209bc17e7c8f8acf5e",
                "applicantCitedExaminerReferenceIndicator": False,
                "citationCategoryCode": "A",
                "citedDocumentIdentifier": "US 20180294126 A1",
                "createDateTime": "2021-12-10T23:10:13Z",
                "createUserIdentifier": "ETL_SYS",
                "examinerCitedReferenceIndicator": True,
                "inventorNameText": "de Leon; Conrado",
                "obsoleteDocumentIdentifier": "KVRDZCSADFLYX10",
                "officeActionCategory": "CTNF",
                "officeActionDate": "2021-11-10T00:00:00Z",
                "patentApplicationNumber": "15931761",
                "qualitySummaryText": "AOK",
                "groupArtUnitNumber": "2835",
                "techCenter": "2800",
                "workGroup": "2830",
            },
        ],
    },
}

0
投票

也许只是我的 Windows 10,但是您认为没有帮助的很长的引用向我显示存在证书错误。 你可以尝试使用

verify=False

response = requests.post(
    'https://developer.uspto.gov/ds-api/enriched_cited_reference_metadata/v2/records',
    headers=headers,
    data=data,
    verify=False
)
© www.soinside.com 2019 - 2024. All rights reserved.