首页 > 解决方案 > 在 Python 中发送 HTTP API 请求并将 json 数据转换为 csv 格式

问题描述

我有 HTTP URL 和 API 请求正文,我需要使用 python 发布请求并以 json 格式获取输出并转换为 csv 文件。因为我是这条蟒蛇的新手,所以无法成功。任何人都可以帮我解决这个问题。

URL:如下 http://{{WEBURL}}:{{WEBPORT}}/{{TENANT_ID}}/api/requesttrackingservice/get

API主体如下

{
  "params": {
    "query": {
      "filters": {
        "typesCriterion": [
          "tasksummaryobject"
        ], 

        "propertiesCriterion": [
          {
            "modifiedDate": {
              "gte": "2019-08-26T06:00:00.000-0500",
               "lte": "2019-08-30T19:00:00.000-0500",
              "type": "_DATETIME"
            }
          }
        ],
            "attributesCriterion": [
          {
            "connectIntegrationType": {
              "eq": "ENTITY_IMPORT"
            }
          },
            {
            "profileName": {
              "eq": "sys_import_data_json_eventhub_task_base"
            }
          }
        ]
      }
    },
    "fields": {
      "attributes": [
        "status","totalRecordsProcessed","totalRecordsCreate","totalRecordsupdate","totalRecordsDelete","filetype"
      ],
      "relationships": [
        "_ALL"
      ]
    },
    "options": {
      "maxRecords": 1000
    }

  }
}

标签: pythonpython-3.xrestapihttprequest

解决方案


将您的 url 分配给一个URL变量,并将您的 json 分配给一个JSON变量,您可以尝试:

import requests
response = requests.post(url=URL, json=JSON)
print(response.content)

推荐阅读