http.py 文件源码

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

项目:uhu 作者: updatehub 项目源码 文件源码
def request(method, url, *args, sign=True, **kwargs):
    custom_ca_certs_file = get_custom_ca_certs_file()

    if custom_ca_certs_file is not None and 'verify' not in kwargs:
        kwargs['verify'] = custom_ca_certs_file

    try:
        if sign:
            response = Request(url, method, *args, **kwargs).send()
        else:
            response = requests.request(
                method, url, *args, timeout=30, **kwargs)
    except HTTPError as error:
        raise error
    except (requests.exceptions.MissingSchema,
            requests.exceptions.InvalidSchema,
            requests.exceptions.URLRequired,
            requests.exceptions.InvalidURL):
        raise HTTPError('You have provided an invalid server URL.')
    except requests.ConnectTimeout:
        raise HTTPError('Connection timed out. Try again later.')
    except requests.ConnectionError:
        raise HTTPError('Server is not available. Try again later.')
    except requests.RequestException:
        raise HTTPError(UNKNOWN_ERROR)
    if response.status_code == 401:
        raise HTTPError('Unautorized. Did you set your credentials?')
    elif not response.ok:
        raise HTTPError(format_server_error(response))
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号