python实现text/html的get请求

先将json转成数据名称(name)和数据值(value)之间以等号相连,与另一组name/value值之间用&相连的形式:

def get_url_format(params):
    if not isinstance(params,dict):
        raise Exception("params必须是字典!")
    params = "?"+"&".join([str(key)+"="+str(value)for key,value in params.items()])
    return params  

再把转换后的参数拼接到请求的url上面: 

def test_api():
body={
"param1":"1234",
"param2":"abcd",
"para2":"222"
}
headers = {"Content-Type": "text/html"}
url = host+ url + get_url_format(body)

res = requests.get(url=url,headers=headers, verify=False)
print(res.json())

原文地址:https://www.cnblogs.com/yetj/p/10748898.html