本文整理汇总了Python中six.moves.http_client.INTERNAL_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python http_client.INTERNAL_SERVER_ERROR属性的具体用法?Python http_client.INTERNAL_SERVER_ERROR怎么用?Python http_client.INTERNAL_SERVER_ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类six.moves.http_client
的用法示例。
在下文中一共展示了http_client.INTERNAL_SERVER_ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _error_result_to_exception
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def _error_result_to_exception(error_result):
"""Maps BigQuery error reasons to an exception.
The reasons and their matching HTTP status codes are documented on
the `troubleshooting errors`_ page.
.. _troubleshooting errors: https://cloud.google.com/bigquery\
/troubleshooting-errors
Args:
error_result (Mapping[str, str]): The error result from BigQuery.
Returns:
google.cloud.exceptions.GoogleCloudError: The mapped exception.
"""
reason = error_result.get("reason")
status_code = _ERROR_REASON_TO_EXCEPTION.get(
reason, http_client.INTERNAL_SERVER_ERROR
)
return exceptions.from_http_status(
status_code, error_result.get("message", ""), errors=[error_result]
)
示例2: test_empty_reply
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_empty_reply():
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False)
def f(status=None, description=None):
inject = dict(reply=suds.byte_str(), status=status,
description=description)
return client.service.f(__inject=inject)
status, reason = f()
assert status == http_client.OK
assert reason is None
status, reason = f(http_client.OK)
assert status == http_client.OK
assert reason is None
status, reason = f(http_client.INTERNAL_SERVER_ERROR)
assert status == http_client.INTERNAL_SERVER_ERROR
assert reason == "injected reply"
status, reason = f(http_client.FORBIDDEN)
assert status == http_client.FORBIDDEN
assert reason == "injected reply"
status, reason = f(http_client.FORBIDDEN, "kwack")
assert status == http_client.FORBIDDEN
assert reason == "kwack"
示例3: test_reply_error_with_detail_without_fault
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_reply_error_with_detail_without_fault():
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=False)
for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR):
status, fault = client.service.f(__inject=dict(
reply=_fault_reply__with_detail, status=http_status))
assert status == http_client.INTERNAL_SERVER_ERROR
_test_fault(fault, True)
status, fault = client.service.f(__inject=dict(
reply=_fault_reply__with_detail, status=http_client.BAD_REQUEST))
assert status == http_client.BAD_REQUEST
assert fault == "injected reply"
status, fault = client.service.f(__inject=dict(
reply=_fault_reply__with_detail, status=http_client.BAD_REQUEST,
description="haleluja"))
assert status == http_client.BAD_REQUEST
assert fault == "haleluja"
示例4: test_reply_error_without_detail_with_fault
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_reply_error_without_detail_with_fault(monkeypatch):
monkeypatch.delitem(locals(), "e", False)
client = testutils.client_from_wsdl(_wsdl__simple_f, faults=True)
for http_status in (http_client.OK, http_client.INTERNAL_SERVER_ERROR):
inject = dict(reply=_fault_reply__without_detail, status=http_status)
e = pytest.raises(suds.WebFault, client.service.f, __inject=inject)
try:
e = e.value
_test_fault(e.fault, False)
assert e.document.__class__ is suds.sax.document.Document
assert str(e) == "Server raised fault: 'Dummy error.'"
finally:
del e # explicitly break circular reference chain in Python 3
inject = dict(reply=_fault_reply__with_detail,
status=http_client.BAD_REQUEST, description="quack-quack")
e = pytest.raises(Exception, client.service.f, __inject=inject).value
try:
assert e.__class__ is Exception
assert e.args[0][0] == http_client.BAD_REQUEST
assert e.args[0][1] == "quack-quack"
finally:
del e # explicitly break circular reference chain in Python 3
示例5: _error
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def _error(self, inner, req):
LOG.error('Middleware error occurred: %s', inner.message)
safe = getattr(inner, 'safe', False)
headers = getattr(inner, 'headers', None)
status = getattr(inner, 'code', http_client.INTERNAL_SERVER_ERROR)
if status is None:
status = http_client.INTERNAL_SERVER_ERROR
msg_dict = dict(url=req.url, status=status)
LOG.info("%(url)s returned with HTTP %(status)d", msg_dict)
outer = self.status_to_type(status)
if headers:
outer.headers = headers
if safe:
msg = (inner.msg if isinstance(inner, exception.KarborException)
else six.text_type(inner))
outer.explanation = msg
return wsgi.Fault(outer)
示例6: server
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def server(self):
"""Provides a test HTTP server.
The test server is automatically created before
a test and destroyed at the end. The server is serving a test
application that can be used to verify requests.
"""
app = flask.Flask(__name__)
app.debug = True
# pylint: disable=unused-variable
# (pylint thinks the flask routes are unusued.)
@app.route("/basic")
def index():
header_value = flask.request.headers.get("x-test-header", "value")
headers = {"X-Test-Header": header_value}
return "Basic Content", http_client.OK, headers
@app.route("/server_error")
def server_error():
return "Error", http_client.INTERNAL_SERVER_ERROR
@app.route("/wait")
def wait():
time.sleep(3)
return "Waited"
# pylint: enable=unused-variable
server = WSGIServer(application=app.wsgi_app)
server.start()
yield server
server.stop()
示例7: test_request_error
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_request_error(self, server):
request = self.make_request()
response = request(url=server.url + "/server_error", method="GET")
assert response.status == http_client.INTERNAL_SERVER_ERROR
assert response.data == b"Error"
示例8: test_success_with_retry
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [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)
示例9: test_retry_exceeds_max_cumulative
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [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)
示例10: unexpected_error
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def unexpected_error(e):
"""Handle exceptions by returning swagger-compliant json."""
logging.exception('An error occured while processing the request.')
response = jsonify({
'code': http_client.INTERNAL_SERVER_ERROR,
'message': 'Exception: {}'.format(e)})
response.status_code = http_client.INTERNAL_SERVER_ERROR
return response
示例11: error_handler
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def error_handler(e):
try:
if isinstance(e, HTTPException):
status_code = e.code
message = e.description if e.description != type(e).description else None
tb = None
else:
status_code = httplib.INTERNAL_SERVER_ERROR
message = None
tb = traceback.format_exc() if current_user.admin else None
if request.is_xhr or request.accept_mimetypes.best in ['application/json', 'text/javascript']:
response = {
'message': message,
'traceback': tb
}
else:
response = render_template('errors/error.html',
title=httplib.responses[status_code],
status_code=status_code,
message=message,
traceback=tb)
except HTTPException as e2:
return error_handler(e2)
return response, status_code
示例12: test_default_error_msg_with_kwargs
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_default_error_msg_with_kwargs(self):
class FakeMasakariException(exception.MasakariException):
msg_fmt = "default message: %(code)s"
exc = FakeMasakariException(code=int(http.INTERNAL_SERVER_ERROR))
self.assertEqual('default message: 500', six.text_type(exc))
self.assertEqual('default message: 500', exc.message)
示例13: test_error_msg_exception_with_kwargs
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_error_msg_exception_with_kwargs(self):
class FakeMasakariException(exception.MasakariException):
msg_fmt = "default message: %(misspelled_code)s"
exc = FakeMasakariException(code=int(http.INTERNAL_SERVER_ERROR),
misspelled_code='blah')
self.assertEqual('default message: blah', six.text_type(exc))
self.assertEqual('default message: blah', exc.message)
示例14: test_error_code_from_kwarg
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_error_code_from_kwarg(self):
class FakeMasakariException(exception.MasakariException):
code = http.INTERNAL_SERVER_ERROR
exc = FakeMasakariException(code=http.NOT_FOUND)
self.assertEqual(exc.kwargs['code'], http.NOT_FOUND)
示例15: test_instantiate_without_title_known_code
# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import INTERNAL_SERVER_ERROR [as 别名]
def test_instantiate_without_title_known_code(self):
exc = exception.ConvertedException(int(http.INTERNAL_SERVER_ERROR))
self.assertEqual(exc.title, status_reasons[http.INTERNAL_SERVER_ERROR])