python如何把request直接输出成json格式化

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/saberpan/article/details/88978112
# encoding:utf-8
import requests
import json

url = "https://qa.zgjdy.cn/c9df55fd12354295a50f0293731ee15s/platform/mobile_ajaxLogin"

payload = "{\n\t\"password\": \"111213\",\n\t\"username\": \"18434392742\"\n}"
headers = {
    'Content-Type': "application/json",
    'cache-control': "no-cache",
    'Postman-Token': "5d235d20-e656-4a23-800d-cd10fd065c1f"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

print(type(response.text))
print(type(json.loads(response.text)))
print(type(json.dumps(json.loads(response.text))))

json1 = json.dumps(json.loads(response.text), indent=4, sort_keys=False, ensure_ascii=False)
print(json1)

f = open("f:/loginapi.txt","w")
print(json1, file = f)

猜你喜欢

转载自blog.csdn.net/saberpan/article/details/88978112