コード例 #1
0
def post(url, data=None, json_data=None, headers={}, encoding='utf-8', decode=True, **kwargs):
    response = requests.post(url, data, json_data, headers=headers.update(default_headers), **kwargs)

    if response.ok:
        byte_array_content = response.content
        return byte_array_content.decode(encoding) if decode and encoding is not None else byte_array_content
    else:
        exc = HTTPException('%s - %s' % (response.status_code, response.reason))
        exc.status = response.status_code
        exc.reason = response.reason
        exc.headers = response.headers
        exc.url = url
        raise exc
コード例 #2
0
def requests_get(url, headers={}, encoding='utf-8', decode=True, **kwargs):
    if url.lower().startswith("ftp://"):
        response = ftp.FTPSession().get(url, **kwargs)
    else:
        response = requests.get(url, headers=headers, **kwargs)

    if response.ok:
        byte_array_content = response.content
        return byte_array_content.decode(encoding) if decode and encoding is not None else byte_array_content
    else:
        exc = HTTPException('%s - %s' % (response.status_code, response.reason))
        exc.status = response.status_code
        exc.reason = response.reason
        exc.headers = response.headers
        exc.url = url
        raise exc