# 传json参数
import requests
url = ‘xxxxxxxx‘
body = {
‘xxx‘: ‘xxx‘,
‘xxx‘: ‘xxx‘
}
# body是json格式的
r = requests.post(url, json=body)
print(r.text)
# 第二种方法
import json
r = requests.post(url, data=json.dumps(body))
print(r.text)
import requests
url = "http://v.juhe.cn/weather/index"
par = {
"cityname": "深圳", # 城市名或城市ID,如:"苏州",需要utf8 urlencode
"dtype": "json", # 返回数据格式:json或xml,默认json
"format": "1", # 未来7天预报(future)两种返回格式,1或2,默认1
"key": "80b4d4e1d870d257d3344fcf2d08f64a" # key须申请
}
r = requests.get(url, params=par)
print(r.text) # json格式的str