本文整理匯總了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
示例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
示例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)
示例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
示例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)
示例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
)
示例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
示例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
示例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)