コード例 #1
0
    def __init__(self, auth):
        self.auth = auth
        self.host = config.get_default('default_requet_host')
        self.api_version = config.get_default('default_api_version')
        self.base_url = 'http://{0}'.format(self.host)

        self.content_type = 'application%2Fjson'
コード例 #2
0
def _init():
    session = requests.Session()
    adapter = requests.adapters.HTTPAdapter(
        pool_connections=config.get_default('connection_pool'),
        pool_maxsize=config.get_default('connection_pool'),
        max_retries=config.get_default('connection_retries'))
    session.mount('http://', adapter)
    global _session
    _session = session
コード例 #3
0
def _get(url, params=None, auth=None):
    try:
        r = requests.get(url,
                         params=params,
                         auth=RequestsAuth(auth) if auth is not None else None,
                         timeout=config.get_default('connection_timeout'),
                         headers=_headers)
    except Exception as e:
        return None, ResponseInfo(None, e)
    return __return_wrapper(r)
コード例 #4
0
def _put(url, data, auth, files=None, headers=None):
    if _session is None:
        _init()
    try:
        post_headers = _headers.copy()
        if headers is not None:
            for k, v in headers.items():
                post_headers.update({k: v})
        r = _session.put(
            url,
            data=data,
            # files=files,
            auth=RequestsAuth(auth),
            headers=post_headers,
            timeout=config.get_default('connection_timeout'))
    except Exception as e:
        return None, ResponseInfo(None, e)
    return __return_wrapper(r)