本文整理匯總了Python中six.moves.http_client.SERVICE_UNAVAILABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Python http_client.SERVICE_UNAVAILABLE屬性的具體用法?Python http_client.SERVICE_UNAVAILABLE怎麽用?Python http_client.SERVICE_UNAVAILABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類six.moves.http_client
的用法示例。
在下文中一共展示了http_client.SERVICE_UNAVAILABLE屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test__process_response_bad_status
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test__process_response_bad_status(self):
upload = _upload.UploadBase(SIMPLE_URL)
_fix_up_virtual(upload)
# Make sure **not finished** before.
assert not upload.finished
status_code = http_client.SERVICE_UNAVAILABLE
response = _make_response(status_code=status_code)
with pytest.raises(common.InvalidResponse) as exc_info:
upload._process_response(response)
error = exc_info.value
assert error.response is response
assert len(error.args) == 4
assert error.args[1] == status_code
assert error.args[3] == http_client.OK
# Make sure **finished** after (even in failure).
assert upload.finished
示例2: setUp
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def setUp(self):
# Sample highly compressible data.
self.sample_data = b'abc' * 200
# Stream of the sample data.
self.sample_stream = six.BytesIO(self.sample_data)
# Sample url_builder.
self.url_builder = base_api._UrlBuilder('http://www.uploads.com')
# Sample request.
self.request = http_wrapper.Request(
'http://www.uploads.com',
headers={'content-type': 'text/plain'})
# Sample successful response.
self.response = http_wrapper.Response(
info={'status': http_client.OK,
'location': 'http://www.uploads.com'},
content='',
request_url='http://www.uploads.com',)
# Sample failure response.
self.fail_response = http_wrapper.Response(
info={'status': http_client.SERVICE_UNAVAILABLE,
'location': 'http://www.uploads.com'},
content='',
request_url='http://www.uploads.com',)
示例3: leave_swarm
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def leave_swarm(self, force=False):
"""
Leave a swarm.
Args:
force (bool): Leave the swarm even if this node is a manager.
Default: ``False``
Returns:
``True`` if the request went through.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
url = self._url('/swarm/leave')
response = self._post(url, params={'force': force})
# Ignore "this node is not part of a swarm" error
if force and response.status_code == http_client.NOT_ACCEPTABLE:
return True
# FIXME: Temporary workaround for 1.13.0-rc bug
# https://github.com/docker/docker/issues/29192
if force and response.status_code == http_client.SERVICE_UNAVAILABLE:
return True
self._raise_for_status(response)
return True
示例4: test_success_with_retry
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test_success_with_retry(self, randint_mock, sleep_mock):
randint_mock.side_effect = [125, 625, 375]
status_codes = (
http_client.INTERNAL_SERVER_ERROR,
http_client.BAD_GATEWAY,
http_client.SERVICE_UNAVAILABLE,
http_client.NOT_FOUND,
)
responses = [_make_response(status_code) for status_code in status_codes]
func = mock.Mock(side_effect=responses, spec=[])
retry_strategy = common.RetryStrategy()
ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy)
assert ret_val == responses[-1]
assert status_codes[-1] not in _helpers.RETRYABLE
assert func.call_count == 4
assert func.mock_calls == [mock.call()] * 4
assert randint_mock.call_count == 3
assert randint_mock.mock_calls == [mock.call(0, 1000)] * 3
assert sleep_mock.call_count == 3
sleep_mock.assert_any_call(1.125)
sleep_mock.assert_any_call(2.625)
sleep_mock.assert_any_call(4.375)
示例5: test_retry_exceeds_max_cumulative
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test_retry_exceeds_max_cumulative(self, randint_mock, sleep_mock):
randint_mock.side_effect = [875, 0, 375, 500, 500, 250, 125]
status_codes = (
http_client.SERVICE_UNAVAILABLE,
http_client.GATEWAY_TIMEOUT,
common.TOO_MANY_REQUESTS,
http_client.INTERNAL_SERVER_ERROR,
http_client.SERVICE_UNAVAILABLE,
http_client.BAD_GATEWAY,
http_client.GATEWAY_TIMEOUT,
common.TOO_MANY_REQUESTS,
)
responses = [_make_response(status_code) for status_code in status_codes]
func = mock.Mock(side_effect=responses, spec=[])
retry_strategy = common.RetryStrategy(max_cumulative_retry=100.0)
ret_val = _helpers.wait_and_retry(func, _get_status_code, retry_strategy)
assert ret_val == responses[-1]
assert status_codes[-1] in _helpers.RETRYABLE
assert func.call_count == 8
assert func.mock_calls == [mock.call()] * 8
assert randint_mock.call_count == 7
assert randint_mock.mock_calls == [mock.call(0, 1000)] * 7
assert sleep_mock.call_count == 7
sleep_mock.assert_any_call(1.875)
sleep_mock.assert_any_call(2.0)
sleep_mock.assert_any_call(4.375)
sleep_mock.assert_any_call(8.5)
sleep_mock.assert_any_call(16.5)
sleep_mock.assert_any_call(32.25)
sleep_mock.assert_any_call(64.125)
示例6: test_create_resumable_upload_session_with_failure
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test_create_resumable_upload_session_with_failure(self):
from google.resumable_media import InvalidResponse
from google.cloud import exceptions
message = "5-oh-3 woe is me."
response = self._mock_requests_response(
status_code=http_client.SERVICE_UNAVAILABLE, headers={}
)
side_effect = InvalidResponse(response, message)
with self.assertRaises(exceptions.ServiceUnavailable) as exc_info:
self._create_resumable_upload_session_helper(side_effect=side_effect)
self.assertIn(message, exc_info.exception.message)
self.assertEqual(exc_info.exception.errors, [])
示例7: test_http_interactions
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test_http_interactions(self, http_503_server):
"""Test interactions with the http server when using hs2-http protocol.
Check that there is an HttpError exception when the server returns a 503 error."""
con = connect("localhost", http_503_server.PORT, use_http_transport=True)
try:
con.cursor()
assert False, "Should have got exception"
except HttpError as e:
assert str(e) == "HTTP code 503: Service Unavailable"
assert e.code == http_client.SERVICE_UNAVAILABLE
assert e.body.decode("utf-8") == "extra text"
示例8: test_retry_on_503
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def test_retry_on_503(self, resp_mock):
"""Test retry for status code that should be retried (e.g. 503)"""
resp_mock.return_value.status_code = http_client.SERVICE_UNAVAILABLE
with self.assertRaises(restclient.MaxRequestRetriesError):
restclient.get('http://foo.com', '/')
示例9: http_503_server
# 需要導入模塊: from six.moves import http_client [as 別名]
# 或者: from six.moves.http_client import SERVICE_UNAVAILABLE [as 別名]
def http_503_server():
class RequestHandler503(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""A custom http handler that checks for duplicate 'Host' headers from the most
recent http request, and always returns a 503 http code"""
def do_POST(self):
# Ensure that only one 'Host' header is contained in the request before responding.
request_headers = None
host_hdr_count = 0
if six.PY2:
# The unfortunately named self.headers here is an instance of mimetools.Message that
# contains the request headers.
request_headers = self.headers.headers
host_hdr_count = sum([header.startswith('Host:') for header in request_headers])
if six.PY3:
# In Python3 self.Headers is an HTTPMessage.
request_headers = self.headers
host_hdr_count = sum([header[0] == 'Host' for header in request_headers.items()])
assert host_hdr_count == 1, "need single 'Host:' header in %s" % request_headers
# Respond with 503.
self.send_response(code=http_client.SERVICE_UNAVAILABLE, message="Service Unavailable")
self.end_headers()
self.wfile.write("extra text".encode('utf-8'))
class TestHTTPServer503(object):
def __init__(self):
self.HOST = "localhost"
self.PORT = get_unused_port()
self.httpd = socketserver.TCPServer((self.HOST, self.PORT), RequestHandler503)
self.http_server_thread = threading.Thread(target=self.httpd.serve_forever)
self.http_server_thread.start()
server = TestHTTPServer503()
yield server
# Cleanup after test.
if server.httpd is not None:
server.httpd.shutdown()
if server.http_server_thread is not None:
server.http_server_thread.join()