当前位置: 首页>>代码示例>>Python>>正文


Python Session.send方法代码示例

本文整理汇总了Python中requests.sessions.Session.send方法的典型用法代码示例。如果您正苦于以下问题:Python Session.send方法的具体用法?Python Session.send怎么用?Python Session.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests.sessions.Session的用法示例。


在下文中一共展示了Session.send方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
 def send(self, request, **kwargs):
     request.url = resolve(request.url)
     # started
     start = datetime.datetime.utcnow()
     res = _Session.send(self, request, **kwargs)
     res.started = start
     res.method = request.method
     _measure(res)
     return res
开发者ID:matrixise,项目名称:loads,代码行数:11,代码来源:measure.py

示例2: send

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
 def send(self, request, **kwargs):
     """Do the actual request from within the session, doing some
     measures at the same time about the request (duration, status, etc).
     """
     # attach some information to the request object for later use.
     start = datetime.datetime.utcnow()
     res = _Session.send(self, request, **kwargs)
     res.started = start
     res.method = request.method
     self._analyse_request(res)
     return res
开发者ID:loads,项目名称:loads-tester,代码行数:13,代码来源:measure.py

示例3: curl

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
 def curl(self, method, endpoint, params=None):
     url = '{scheme}://{host}{endpoint}'.format(scheme=self.SCHEME, host=self.HOST, endpoint=endpoint)
     params = params or {}
     session = Session()
     request = Request(method, url, params=params)
     request = request.prepare()
     request.headers.update({
         'X-Application-Key': self.KEY,
     })
     response = session.send(request)
     return GforceResponse(response)
开发者ID:quaspas,项目名称:Gforce,代码行数:13,代码来源:client.py

示例4: send

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
    def send(self, request, **kwargs):
        """Do the actual request from within the session, doing some
        measures at the same time about the request (duration, status, etc).
        """
        if not request.url.startswith('https://'):
            request.url, original, resolved = dns_resolve(request.url)
            request.headers['Host'] = original

        # attach some information to the request object for later use.
        start = datetime.datetime.utcnow()
        res = _Session.send(self, request, **kwargs)
        res.started = start
        res.method = request.method
        self._analyse_request(res)
        return res
开发者ID:diyan,项目名称:loads,代码行数:17,代码来源:measure.py

示例5: APIClient

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
class APIClient(BaseAPIClient):
    verify = True
    base_url = None

    def __init__(self, *args, **kwargs):
        self.session = Session()
        spec = self.call(SpecEndpoint())
        super(APIClient, self).__init__(*args, spec=spec, **kwargs)

    def make_request(self, endpoint, request):
        request.url = self.base_url + request.url
        prepared = self.session.prepare_request(request)
        return self.session.send(prepared,
                                 stream=False,
                                 timeout=None,
                                 verify=self.verify,
                                 cert=None,
                                 proxies={},
                                 allow_redirects=True)
开发者ID:cosmic-api,项目名称:cosmic.py,代码行数:21,代码来源:client.py

示例6: Endpoint

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
class Endpoint(object):
    """
    Represents an endpoint for a particular service in a specific
    region.  Only an endpoint can make requests.

    :ivar service: The Service object that describes this endpoints
        service.
    :ivar host: The fully qualified endpoint hostname.
    :ivar session: The session object.
    """

    def __init__(self, service, region_name, host, auth, proxies=None):
        self.service = service
        self.session = self.service.session
        self.region_name = region_name
        self.host = host
        self.verify = True
        self.auth = auth
        if proxies is None:
            proxies = {}
        self.proxies = proxies
        self.http_session = Session()

    def __repr__(self):
        return "%s(%s)" % (self.service.endpoint_prefix, self.host)

    def make_request(self, params, list_marker=None):
        raise NotImplementedError("make_request")

    def prepare_request(self, request):
        logger.debug("prepare_request")
        if self.auth is not None:
            self.auth.add_auth(request=request)
        prepared_request = request.prepare()
        return prepared_request

    def _send_request(self, request, operation):
        return self.http_session.send(
            request, verify=self.verify, stream=operation.is_streaming(), proxies=self.proxies
        )
开发者ID:jonparrott,项目名称:botocore,代码行数:42,代码来源:endpoint.py

示例7: Endpoint

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
class Endpoint(object):
    """
    Represents an endpoint for a particular service in a specific
    region.  Only an endpoint can make requests.

    :ivar service: The Service object that describes this endpoints
        service.
    :ivar host: The fully qualified endpoint hostname.
    :ivar session: The session object.
    """

    def __init__(self, service, region_name, host, auth, proxies=None):
        self.service = service
        self.session = self.service.session
        self.region_name = region_name
        self.host = host
        self.verify = True
        self.auth = auth
        if proxies is None:
            proxies = {}
        self.proxies = proxies
        self.http_session = Session()
        self._lock = threading.Lock()

    def __repr__(self):
        return '%s(%s)' % (self.service.endpoint_prefix, self.host)

    def make_request(self, operation, params):
        logger.debug("Making request for %s (verify_ssl=%s) with params: %s",
                     operation, self.verify, params)
        request = self._create_request_object(operation, params)
        prepared_request = self.prepare_request(request)
        return self._send_request(prepared_request, operation)

    def _create_request_object(self, operation, params):
        raise NotImplementedError('_create_request_object')

    def prepare_request(self, request):
        if self.auth is not None:
            with self._lock:
                # Parts of the auth signing code aren't thread safe (things
                # that manipulate .auth_path), so we're using a lock here to
                # prevent race conditions.
                event = self.session.create_event(
                    'before-auth', self.service.endpoint_prefix)
                self.session.emit(event, endpoint=self,
                                request=request, auth=self.auth)
                self.auth.add_auth(request=request)
        prepared_request = request.prepare()
        return prepared_request

    def _send_request(self, request, operation):
        attempts = 1
        response, exception = self._get_response(request, operation, attempts)
        while self._needs_retry(attempts, operation, response, exception):
            attempts += 1
            # If there is a stream associated with the request, we need
            # to reset it before attempting to send the request again.
            # This will ensure that we resend the entire contents of the
            # body.
            request.reset_stream()
            response, exception = self._get_response(request, operation,
                                                     attempts)
        return response

    def _get_response(self, request, operation, attempts):
        try:
            logger.debug("Sending http request: %s", request)
            http_response = self.http_session.send(
                request, verify=self.verify,
                stream=operation.is_streaming(),
                proxies=self.proxies)
        except Exception as e:
            return (None, e)
        # This returns the http_response and the parsed_data.
        return (botocore.response.get_response(self.session, operation,
                                               http_response), None)

    def _needs_retry(self, attempts, operation, response=None,
                     caught_exception=None):
        event = self.session.create_event(
            'needs-retry', self.service.endpoint_prefix, operation.name)
        handler_response = self.session.emit_first_non_none_response(
            event, response=response, endpoint=self,
            operation=operation, attempts=attempts,
            caught_exception=caught_exception)
        if handler_response is None:
            return False
        else:
            # Request needs to be retried, and we need to sleep
            # for the specified number of times.
            logger.debug("Response received to retry, sleeping for "
                         "%s seconds", handler_response)
            time.sleep(handler_response)
            return True
开发者ID:Debian,项目名称:botocore,代码行数:97,代码来源:endpoint.py

示例8: Endpoint

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
class Endpoint(object):
    """
    Represents an endpoint for a particular service in a specific
    region.  Only an endpoint can make requests.

    :ivar service: The Service object that describes this endpoints
        service.
    :ivar host: The fully qualified endpoint hostname.
    :ivar session: The session object.
    """

    def __init__(self, service, region_name, host, auth, proxies=None):
        self.service = service
        self.session = self.service.session
        self.region_name = region_name
        self.host = host
        self.verify = True
        self.auth = auth
        if proxies is None:
            proxies = {}
        self.proxies = proxies
        self.http_session = Session()

    def __repr__(self):
        return "%s(%s)" % (self.service.endpoint_prefix, self.host)

    def make_request(self, operation, params):
        logger.debug("Making request for %s (verify_ssl=%s) with params: %s", operation, self.verify, params)
        request = self._create_request_object(operation, params)
        prepared_request = self.prepare_request(request)
        return self._send_request(prepared_request, operation)

    def _create_request_object(self, operation, params):
        raise NotImplementedError("_create_request_object")

    def prepare_request(self, request):
        if self.auth is not None:
            event = self.session.create_event("before-auth", self.service.endpoint_prefix)
            self.session.emit(event, endpoint=self, request=request, auth=self.auth)
            self.auth.add_auth(request=request)
        prepared_request = request.prepare()
        return prepared_request

    def _send_request(self, request, operation):
        attempts = 1
        response, exception = self._get_response(request, operation, attempts)
        while self._needs_retry(attempts, operation, response, exception):
            attempts += 1
            response, exception = self._get_response(request, operation, attempts)
        return response

    def _get_response(self, request, operation, attempts):
        try:
            logger.debug("Sending http request: %s", request)
            http_response = self.http_session.send(
                request, verify=self.verify, stream=operation.is_streaming(), proxies=self.proxies
            )
        except Exception as e:
            return (None, e)
        # This returns the http_response and the parsed_data.
        return (botocore.response.get_response(self.session, operation, http_response), None)

    def _needs_retry(self, attempts, operation, response=None, caught_exception=None):
        event = self.session.create_event("needs-retry", self.service.endpoint_prefix, operation.name)
        handler_response = self.session.emit_first_non_none_response(
            event,
            response=response,
            endpoint=self,
            operation=operation,
            attempts=attempts,
            caught_exception=caught_exception,
        )
        if handler_response is None:
            return False
        else:
            # Request needs to be retried, and we need to sleep
            # for the specified number of times.
            logger.debug("Response received to retry, sleeping for " "%s seconds", handler_response)
            time.sleep(handler_response)
            return True
开发者ID:jjjake,项目名称:botocore,代码行数:82,代码来源:endpoint.py

示例9: send

# 需要导入模块: from requests.sessions import Session [as 别名]
# 或者: from requests.sessions.Session import send [as 别名]
 def send(self, request):
     session = Session()
     response = session.send(request)
     return BrandStemResponse(response)
开发者ID:stjosephcontent,项目名称:python-brandstem,代码行数:6,代码来源:client.py


注:本文中的requests.sessions.Session.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。