json 如何解决它尝试解决它

lqfhib0f  于 2023-02-26  发布在  其他
关注(0)|答案(2)|浏览(187)

编写一个python网络客户端来访问一个网上超市的API。API的详细信息如下所示。
Base URL= http://host1.open.uom.lk:8080
Route Table

编写一个python程序来创建一个新产品,其中包含以下JSON格式的信息。打印请求的响应代码。

{
        "productName":"Araliya Basmathi Rice",
        "description":"White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
        "category":"Rice",
        "brand":"CIC",
        "expiredDate":"2023.05.04",
        "manufacturedDate":"2022.02.20",
        "batchNumber":324567,
        "unitPrice":1020,
        "quantity":200,
        "createdDate":"2022.02.24"
}
bvpmtnay

bvpmtnay1#

import requests

data = { "productName":"Araliya Basmathi Rice", "description":"White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.", "category":"Rice", "brand":"CIC", "expiredDate":"2023.05.04", "manufacturedDate":"2022.02.20", "batchNumber":324567, "unitPrice":1020, "quantity":200, "createdDate":"2022.02.24" }

res = requests.post("http://host1.open.uom.lk:8080/api/products", json = data)
print(res)

这很管用

k3bvogb1

k3bvogb12#

这就是答案:输入请求
导入json
基本网址="www.example.com"http://host1.open.uom.lk:8080"
更新的实体={
"产品名称":"阿拉利亚巴斯马蒂大米",
"描述":"从巴基斯坦进口的巴斯马蒂白大米。高品质大米,额外的香味。有机种植。",
"类别":"大米",
"品牌":"中投",
"失效日期":"2023年5月4日",
"生产日期":"2022年2月20日",
"批号":324567,
"单价":1020,
【数量】:200个,
"创建日期":"2022年2月24日"
}
响应= www.example.com(f "{基础网址}/api/产品/",json =更新的实体)打印(响应状态代码)requests.post(f"{BASE_URL}/api/products/", json=updated_entity) print(response.status_code)

相关问题