python 封装的post方法

import requests
import json


# 发送post请求
def post(url, headers, values):
    try:
        headers['Content-Type'] = "application/json; charset=utf-8"
        response = requests.post(
            url=url,
            headers=headers,
            data=json.dumps(values)
        )
        return json.loads(response.content)
    except requests.exceptions.RequestException, e:
        print('HTTP Request failed :', url, values)
        print e

猜你喜欢

转载自www.cnblogs.com/qiqi-yhq/p/12069386.html