python 封装的post方法

Posted 云深不知处

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于python 封装的post方法的主要内容,如果未能解决你的问题,请参考以下文章