python - 在 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
}
}
}
解决方案
将您的 url 分配给一个URL
变量,并将您的 json 分配给一个JSON
变量,您可以尝试:
import requests
response = requests.post(url=URL, json=JSON)
print(response.content)
推荐阅读
- testing - 使用 TestCafe 选择器,如何验证 <select> 中所选项目的文本?
- reactjs - 如果没有连接,则显示小吃吧
- java - 关于如何将数据键入移动应用程序的盒装空间的建议
- python - 我必须从多个文本文件(.txt)中识别段落并创建一个数据框 [paragraph1, "text of the file1 in paragraphs"]
- python-3.x - Altair 中具有自定义置信区间的折线图
- oracle - java.sql.SQLDataException: ORA-01830: 日期格式图片在转换整个输入字符串之前结束 (Oracle)
- javascript - 我必须在 D3 中使用“+(x)+”、“+(y)+”什么?而不是使用 d3.event.x&d3.event.y?
- python - 使用参数返回不同值的 Lambda 函数
- winapi - 如何在 Direct2D 窗口应用程序中使用 DXGI 翻转模型?
- scala - 在 Scala 中处理两个选项