http.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:OpenAPI-Python 作者: KKBOX 项目源码 文件源码
def _do_post(self, url, data, headers):
        try:  # Python 3
            if data != None:
                data = bytes(data, 'utf-8')
        except:  # Python 2
            pass

        try:
            req = url_request.Request(url=url, data=data, headers=headers)
            req.add_header('User-Agent', KKBOXHTTP.USER_AGENT)
            f = url_request.urlopen(req)
            r = f.read()
        except url_request.HTTPError as e:
            print(e.fp.read())
            raise (e)
        except Exception as e:
            raise (e)

        try:  # Python 3
            r = str(r, 'utf-8')
        except:  # Python 2
            pass

        json_object = json.loads(r)
        return json_object
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号