本文整理汇总了Python中elasticsearch.transport.Transport.perform_request方法的典型用法代码示例。如果您正苦于以下问题:Python Transport.perform_request方法的具体用法?Python Transport.perform_request怎么用?Python Transport.perform_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类elasticsearch.transport.Transport
的用法示例。
在下文中一共展示了Transport.perform_request方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_body_bytes_get_passed_untouched
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_body_bytes_get_passed_untouched(self):
t = Transport([{}], connection_class=DummyConnection)
body = b'\xe4\xbd\xa0\xe5\xa5\xbd'
t.perform_request('GET', '/', body=body)
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', None, body), t.get_connection().calls[0][0])
示例2: test_request_timeout_extracted_from_params_and_passed
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_request_timeout_extracted_from_params_and_passed(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request('GET', '/', params={'request_timeout': 42})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', {}, None), t.get_connection().calls[0][0])
self.assertEquals({'timeout': 42, 'ignore': ()}, t.get_connection().calls[0][1])
示例3: test_send_get_body_as_source
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_send_get_body_as_source(self):
t = Transport([{}], send_get_body_as="source", connection_class=DummyConnection)
t.perform_request("GET", "/", body={})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(
("GET", "/", {"source": "{}"}, None), t.get_connection().calls[0][0]
)
示例4: test_resurrected_connection_will_be_marked_as_live_on_success
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_resurrected_connection_will_be_marked_as_live_on_success(self):
t = Transport([{}], connection_class=DummyConnection)
con = t.connection_pool.get_connection()
t.connection_pool.mark_dead(con)
t.perform_request('GET', '/')
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals(0, len(t.connection_pool.dead_count))
示例5: test_body_surrogates_replaced_encoded_into_bytes
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_body_surrogates_replaced_encoded_into_bytes(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request("GET", "/", body="你好\uda6a")
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(
("GET", "/", None, b"\xe4\xbd\xa0\xe5\xa5\xbd\xed\xa9\xaa"),
t.get_connection().calls[0][0],
)
示例6: test_request_timeout_extracted_from_params_and_passed
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_request_timeout_extracted_from_params_and_passed(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request("GET", "/", params={"request_timeout": 42})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(("GET", "/", {}, None), t.get_connection().calls[0][0])
self.assertEquals(
{"timeout": 42, "ignore": (), "headers": None},
t.get_connection().calls[0][1],
)
示例7: test_sniff_after_n_seconds
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_sniff_after_n_seconds(self):
t = Transport([{"data": CLUSTER_NODES}], connection_class=DummyConnection, sniffer_timeout=5)
for _ in range(4):
t.perform_request("GET", "/")
self.assertEquals(1, len(t.connection_pool.connections))
self.assertIsInstance(t.get_connection(), DummyConnection)
t.last_sniff = time.time() - 5.1
t.perform_request("GET", "/")
self.assertEquals(1, len(t.connection_pool.connections))
self.assertEquals("http://1.1.1.1:123", t.get_connection().host)
self.assertTrue(time.time() - 1 < t.last_sniff < time.time() + 0.01)
示例8: test_body_gets_encoded_into_bytes
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_body_gets_encoded_into_bytes(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request('GET', '/', body='你好')
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', None, b'\xe4\xbd\xa0\xe5\xa5\xbd'), t.get_connection().calls[0][0])
示例9: test_send_get_body_as_post
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_send_get_body_as_post(self):
t = Transport([{}], send_get_body_as='POST', connection_class=DummyConnection)
t.perform_request('GET', '/', body={})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('POST', '/', None, b'{}'), t.get_connection().calls[0][0])
示例10: test_send_get_body_as_source
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_send_get_body_as_source(self):
t = Transport([{}], send_get_body_as='source', connection_class=DummyConnection)
t.perform_request('GET', '/', body={})
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(('GET', '/', {'source': '{}'}, None), t.get_connection().calls[0][0])
示例11: ElasticSearch
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
#.........这里部分代码省略.........
"""
Send an HTTP request to ES, and return the JSON-decoded response.
This is mostly an internal method, but it also comes in handy if you
need to use a brand new ES API that isn't yet explicitly supported by
pyelasticsearch, while still taking advantage of our connection pooling
and retrying.
Retry the request on different servers if the first one is down and
the ``max_retries`` constructor arg was > 0.
On failure, raise an
:class:`~pyelasticsearch.exceptions.ElasticHttpError`, a
:class:`~pyelasticsearch.exceptions.ConnectionError`, or a
:class:`~pyelasticsearch.exceptions.Timeout`.
:arg method: An HTTP method, like "GET"
:arg path_components: An iterable of path components, to be joined by
"/"
:arg body: A map of key/value pairs to be sent as the JSON request
body. Alternatively, a string to be sent verbatim, without further
JSON encoding.
:arg query_params: A map of querystring param names to values or
``None``
"""
if query_params is None:
query_params = {}
path = self._join_path(path_components)
# We wrap to use pyelasticsearch's exception hierarchy for backward
# compatibility:
try:
# This implicitly converts dicts to JSON. Strings are left alone:
_, prepped_response = self._transport.perform_request(
method,
path,
params=dict((k, self._utf8(self._to_query(v))) for k, v in iteritems(query_params)),
body=body,
)
except SerializationError as exc:
raise InvalidJsonResponseError(exc.args[0])
except (ConnectionError, ConnectionTimeout) as exc:
# Pull the urllib3-native exception out, and raise it:
raise exc.info
except TransportError as exc:
status = exc.args[0]
error_message = exc.args[1]
self._raise_exception(status, error_message)
return prepped_response
def _raise_exception(self, status, error_message):
"""Raise an exception based on an error-indicating response from ES."""
error_class = ElasticHttpError
if status == 404:
error_class = ElasticHttpNotFoundError
elif hasattr(error_message, "startswith") and (
error_message.startswith("IndexAlreadyExistsException")
or "nested: IndexAlreadyExistsException" in error_message
):
error_class = IndexAlreadyExistsError
raise error_class(status, error_message)
def _encode_json(self, value):
"""
示例12: ElasticSearch
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
#.........这里部分代码省略.........
body='',
query_params=None):
"""
Send an HTTP request to ES, and return the JSON-decoded response.
This is mostly an internal method, but it also comes in handy if you
need to use a brand new ES API that isn't yet explicitly supported by
pyelasticsearch, while still taking advantage of our connection pooling
and retrying.
Retry the request on different servers if the first one is down and
the ``max_retries`` constructor arg was > 0.
On failure, raise an
:class:`~pyelasticsearch.exceptions.ElasticHttpError`, a
:class:`~pyelasticsearch.exceptions.ConnectionError`, or a
:class:`~pyelasticsearch.exceptions.Timeout`.
:arg method: An HTTP method, like "GET"
:arg path_components: An iterable of path components, to be joined by
"/"
:arg body: A map of key/value pairs to be sent as the JSON request
body. Alternatively, a string to be sent verbatim, without further
JSON encoding.
:arg query_params: A map of querystring param names to values or
``None``
"""
path = self._join_path(path_components)
# We wrap to use pyelasticsearch's exception hierarchy for backward
# compatibility:
try:
# This implicitly converts dicts to JSON. Strings are left alone:
_, prepped_response = self._transport.perform_request(
method,
path,
params=dict((k, self._utf8(self._to_query(v)))
for k, v in iteritems(query_params)) if query_params else None,
body=body)
except SerializationError as exc:
raise InvalidJsonResponseError(exc.args[0])
except (ConnectionError, ConnectionTimeout) as exc:
# Pull the urllib3-native exception out, and raise it:
raise exc.info
except TransportError as exc:
status = exc.args[0]
error_message = exc.args[1]
self._raise_exception(status, error_message)
return prepped_response
def _raise_exception(self, status, error_message):
"""Raise an exception based on an error-indicating response from ES."""
error_class = ElasticHttpError
if status == 404:
error_class = ElasticHttpNotFoundError
elif (hasattr(error_message, 'startswith') and
(error_message.startswith('IndexAlreadyExistsException') or
'nested: IndexAlreadyExistsException' in error_message)):
error_class = IndexAlreadyExistsError
raise error_class(status, error_message)
def _encode_json(self, value):
"""
Convert a Python value to a form suitable for ElasticSearch's JSON DSL.
示例13: test_body_gets_encoded_into_bytes
# 需要导入模块: from elasticsearch.transport import Transport [as 别名]
# 或者: from elasticsearch.transport.Transport import perform_request [as 别名]
def test_body_gets_encoded_into_bytes(self):
t = Transport([{}], connection_class=DummyConnection)
t.perform_request("GET", "/", body=u"你好")
self.assertEquals(1, len(t.get_connection().calls))
self.assertEquals(("GET", "/", None, b"\xe4\xbd\xa0\xe5\xa5\xbd"), t.get_connection().calls[0][0])