我尝试在此网站上发布一些数据,当我在 Pycharm 上运行时,它得到了。
{
"args": {},
"data": "",
"files": {},
"form": {
"a": "1",
"id": "123",
"model": "a12",
"name": "John",
"number": "456",
"status": "OK"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "51",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.32.3",
"X-Amzn-Trace-Id": "Root=1-66d82479-64115df475c1d2fc14803b3c"
},
"json": null,
"origin": "117.0.114.106",
"url": "https://httpbin.org/post"
}
但是当我尝试使用 Postman 时,除了 JSON 数据之外,它仍然正常(200),并且我可以只打印“input.json”中的数据吗?这是我的代码
import requests
import json
with open('input.json','r') as f:
file_data = json.load(f)
r = requests.get("https://httpbin.org/get", data=file_data)
print(r.text)
我只是想仔细检查我的数据是否已发布在双方。
这段代码对我有用。我刚刚将
null
替换为 None
:
导入请求
数据={ “参数”:{}, “数据”: ””, “文件”:{}, “形式”: { “一”:“1”, “id”:“123”, “型号”:“a12”, “姓名”:“约翰”, “数量”:“456”, “状态”:“正常” }, “标题”:{ “接受”:“/”, "接受编码": "gzip, deflate", “内容长度”:“51”, "内容类型": "application/x-www-form-urlencoded", “主机”:“httpbin.org”, “用户代理”:“python-requests/2.32.3”, “X-Amzn-Trace-Id”:“根=1-66d82479-64115df475c1d2fc14803b3c” }, “json”:无, “来源”:“117.0.114.106”, “url”:“https://httpbin.org/post” }
r = requests.get("https://httpbin.org/get", data=data)
打印(r.text)