1.requests 接口请求方式 git git_requests = requests.git(url=url, params=params,)
post_requests = requests.post(url=url,headers=headers
)
2.json 数据转换 1.字符串转化为 json
def add_name_create(self):
data = {"tag": {"name": "1tang单\22中5435文13hh3jk"}}
data_str = json.dumps(data, ensure_ascii=False)
params = token_ko().huoqu_token()
add = requests.post(url="https://api.weixin.qq.com/cgi-bin/tags/create", data=data_str.encode('utf-8'), params=params) print(add.text)
3.json 数据 1 json 转化为 字符串
class token_ko:
def huoqu_token(self):
params = {
"grant_type": "**",
"appid": "**",
"secret": "***"
}
token_obj = requests.get(url="https://api.weixin.qq.com/cgi-bin/token",
params=params)
str = token_obj.text # 打印出来是str类型 给str对象
str_json = json.loads(str) # 利用 loads 关键字 将字符串转化为json
# huoqu_json = jsonpath.jsonpath(str_json, '$.access_token')[0]
# print(type(str_json), str_json)
return str_json
ok = token_ko()
ok.huoqu_token()