utils.py 文件源码

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

项目:tornaqiniu 作者: free-free 项目源码 文件源码
def send_sync_request(url, headers=None, method="GET", body=None):
    headers = headers or {}
    if body or method.upper() == "POST":
        if "Content-Type" not in headers:
            headers["Content-Type"] = "application/x-www-form-urlencoded"
    req = httpclient.HTTPRequest(
        url, method=method, body=body, headers=headers, allow_nonstandard_methods=True)
    http_client = httpclient.HTTPClient()
    response = ""
    try:
        response = http_client.fetch(req)
        return response
    except httpclient.HTTPError as e:
        print("Error:" + str(e))
        raise httpclient.HTTPError()
    except Exception as e:
        print("Error:" + str(e))
        raise Exception
    finally:
        http_client.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号