本文整理汇总了Python中httplib.INTERNAL_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python httplib.INTERNAL_SERVER_ERROR属性的具体用法?Python httplib.INTERNAL_SERVER_ERROR怎么用?Python httplib.INTERNAL_SERVER_ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类httplib
的用法示例。
在下文中一共展示了httplib.INTERNAL_SERVER_ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_client_bad_request_with_parameters
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def test_client_bad_request_with_parameters(jedihttp):
filepath = utils.fixture_filepath('goto.py')
request_data = {
'source': read_file(filepath),
'line': 100,
'col': 1,
'source_path': filepath
}
response = requests.post(
'http://127.0.0.1:{0}/gotodefinition'.format(PORT),
json=request_data,
auth=HmacAuth(SECRET))
assert_that(response.status_code, equal_to(httplib.INTERNAL_SERVER_ERROR))
hmachelper = hmaclib.JediHTTPHmacHelper(SECRET)
assert_that(hmachelper.is_response_authenticated(response.headers,
response.content))
示例2: capture_exception
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def capture_exception(callback, request, url_parts):
"""
execute `callback` with `request` and `path_parts` parameters
and handles exceptions generated from `callback`
Args:
callback (function): the callback function to execute
request ([type]): the request object being passed in from rest handler
path_parts ([type]): the url parts passed in from rest handler
Returns:
dict
"""
try:
return callback(request, url_parts)
except (SplunkRestProxyException, SplunkRestException) as e:
return e.to_http_response()
except Exception as e:
return SplunkRestProxyException('Can not complete the request: %s' % str(e), logging.ERROR, httplib.INTERNAL_SERVER_ERROR).to_http_response()
示例3: post
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def post(self, blockable_id): # pylint: disable=g-bad-name
"""Post handler for blockables."""
blockable_id = blockable_id.lower()
logging.info('Blockable handler POST input: %s', self.request.arguments())
if self.request.get('recount').lower() == 'recount':
try:
voting_api.Recount(blockable_id)
except voting_api.BlockableNotFoundError:
self.abort(httplib.NOT_FOUND, explanation='Blockable not found')
except voting_api.UnsupportedClientError:
self.abort(httplib.BAD_REQUEST, explanation='Unsupported client')
except Exception as e: # pylint: disable=broad-except
self.abort(httplib.INTERNAL_SERVER_ERROR, explanation=e.message)
else:
blockable = binary_models.Blockable.get_by_id(blockable_id)
self.respond_json(blockable)
elif self.request.get('reset').lower() == 'reset':
self._reset_blockable(blockable_id)
else:
self._insert_blockable(blockable_id, datetime.datetime.utcnow())
示例4: post
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def post(self, host_id):
if not self.exm:
self.abort(httplib.NOT_FOUND, explanation='Exemption not found')
# Extract and validate POST data fields.
justification = self.request.get('justification')
if not justification:
self.abort(
httplib.BAD_REQUEST,
explanation='No justification for revoking exemption provided')
try:
exemption_api.Revoke(self.exm.key, [justification])
except Exception: # pylint: disable=broad-except
logging.exception(
'Error encountered while revoking Exemption for host %s', host_id)
self.abort(
httplib.INTERNAL_SERVER_ERROR,
explanation='Error while revoking exemption')
self._RespondWithExemptionAndTransitiveState(self.exm.key)
示例5: insert_role
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def insert_role(self, name=_ROLE_NAME, customer_id='my_customer'):
"""Creates and inserts a new GSuite Admin Role.
Args:
name: str, the name of the new GSuite Admin Role.
customer_id: str, the G Suite customer ID to insert the role into.
Returns:
A dictionary object representing the new GSuite Admin Role.
https://developers.google.com/admin-sdk/directory/v1/reference/roles
Raises:
AlreadyExistsError: when the role with the provided name already exists.
ForbiddenError: when authorization fails.
InsertionError: when creation fails (e.g. failed to authenticate, improper
scopes, etc).
"""
try:
return self._client.roles().insert(
customer=customer_id,
body={
'roleName': name,
'rolePrivileges': _ROLE_PRIVILEGES,
'roleDescription': _ROLE_DESCRIPTION,
'isSystemRole': False,
'isSuperAdminRole': False,
},
).execute()
except errors.HttpError as err:
status = err.resp.status
if (status == http_status.CONFLICT or
status == http_status.INTERNAL_SERVER_ERROR):
raise AlreadyExistsError(
'role with name {!r} already exists'.format(name))
if status == http_status.FORBIDDEN:
raise ForbiddenError(_FORBIDDEN_ERROR_MSG)
logging.error(_INSERT_ROLE_ERROR_MSG, name, err)
raise InsertionError(_INSERT_ROLE_ERROR_MSG % (name, err))
示例6: test_get_urlfetch_error
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def test_get_urlfetch_error(self, mock_config, mock_urlfetch):
mock_config.side_effect = ['gcp_bucket_name', True]
response = self.testapp.get(self._CRON_URL, expect_errors=True)
self.assertEqual(response.status_int, httplib.INTERNAL_SERVER_ERROR)
示例7: ReadDataFile
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def ReadDataFile(data_path, openfile=file):
"""Reads a file on disk, returning a corresponding HTTP status and data.
Args:
data_path: Path to the file on disk to read.
openfile: Used for dependency injection.
Returns:
Tuple (status, data) where status is an HTTP response code, and data is
the data read; will be an empty string if an error occurred or the
file was empty.
"""
status = httplib.INTERNAL_SERVER_ERROR
data = ""
try:
data_file = openfile(data_path, 'rb')
try:
data = data_file.read()
finally:
data_file.close()
status = httplib.OK
except (OSError, IOError), e:
logging.error('Error encountered reading file "%s":\n%s', data_path, e)
if e.errno in FILE_MISSING_EXCEPTIONS:
status = httplib.NOT_FOUND
else:
status = httplib.FORBIDDEN
示例8: handle_one_request
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def handle_one_request(self):
"""Override. Invoked from BaseHTTPRequestHandler constructor."""
self.raw_requestline = self.rfile.readline()
if not self.raw_requestline:
self.close_connection = 1
return
if not self.parse_request():
return
process = GlobalProcess()
balance_set = process.GetBalanceSet()
request_size = int(self.headers.get('content-length', 0))
payload = self.rfile.read(request_size)
for port in balance_set:
logging.debug('balancer to port %d', port)
connection = self.connection_handler(process.host, port=port)
connection.response_class = ForwardResponse
connection.request(self.command, self.path, payload, dict(self.headers))
try:
response = connection.getresponse()
except httplib.HTTPException, e:
self.send_error(httplib.INTERNAL_SERVER_ERROR, str(e))
return
if response.status != httplib.SERVICE_UNAVAILABLE:
self.wfile.write(response.data)
return
示例9: __init__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def __init__(self):
self.api_key_valid = True
self.response_code = httplib.INTERNAL_SERVER_ERROR
self.response_size = report_request.NOT_SET
self.request_size = report_request.NOT_SET
self.http_method = None
self.url = None
示例10: test_should_include_detail_in_error_text_when_needed
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def test_should_include_detail_in_error_text_when_needed(self):
detail = u'details, details, details'
resp = sc_messages.AllocateQuotaResponse(
allocateErrors = [
sc_messages.QuotaError(
code=sc_messages.QuotaError.CodeValueValuesEnum.OUT_OF_RANGE,
description=detail)
]
)
code, got = quota_request.convert_response(resp, self.PROJECT_ID)
expect(code).to(equal(httplib.INTERNAL_SERVER_ERROR))
assert got.endswith(detail)
示例11: showHttpErrorCodes
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def showHttpErrorCodes():
"""
Shows all HTTP error codes raised till now
"""
if kb.httpErrorCodes:
warnMsg = "HTTP error codes detected during run:\n"
warnMsg += ", ".join("%d (%s) - %d times" % (code, httplib.responses[code] \
if code in httplib.responses else '?', count) \
for code, count in kb.httpErrorCodes.items())
logger.warn(warnMsg)
if any((str(_).startswith('4') or str(_).startswith('5')) and _ != httplib.INTERNAL_SERVER_ERROR and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()):
msg = "too many 4xx and/or 5xx HTTP error codes "
msg += "could mean that some kind of protection is involved (e.g. WAF)"
logger.debug(msg)
示例12: _not_found
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def _not_found(self, response, code_error=None):
if code_error is None:
code_error = self.CODE_ERROR_NOT_FOUND
valid_response(response, status_code=httplib.INTERNAL_SERVER_ERROR)
assert_response_error(response, codigo=code_error)
示例13: _attr_invalid
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def _attr_invalid(self, response, code_error=None):
if code_error is None:
code_error = CodeError.INVALID_VALUE_ERROR
valid_response(response, status_code=httplib.INTERNAL_SERVER_ERROR)
assert_response_error(response, codigo=code_error)
示例14: test_bad_app
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def test_bad_app(self):
"""Make sure the server handles a bad servicer implementation."""
req = test_pb2.GiveRequest(m=825800)
resp = self.bad_app.post(
'/prpc/test.Test/Give',
req.SerializeToString(),
self.make_headers(encoding.Encoding.BINARY),
expect_errors=True,
)
self.assertEqual(resp.status_int, httplib.INTERNAL_SERVER_ERROR)
self.check_headers(resp.headers, server.StatusCode.INTERNAL)
req = empty_pb2.Empty()
resp = self.bad_app.post(
'/prpc/test.Test/Take',
req.SerializeToString(),
self.make_headers(encoding.Encoding.BINARY),
expect_errors=True,
)
self.assertEqual(resp.status_int, httplib.INTERNAL_SERVER_ERROR)
self.check_headers(resp.headers, server.StatusCode.INTERNAL)
req = test_pb2.EchoRequest()
resp = self.bad_app.post(
'/prpc/test.Test/Echo',
req.SerializeToString(),
self.make_headers(encoding.Encoding.BINARY),
expect_errors=True,
)
self.assertEqual(resp.status_int, httplib.INTERNAL_SERVER_ERROR)
self.check_headers(resp.headers, server.StatusCode.INTERNAL)
示例15: to_http_response
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import INTERNAL_SERVER_ERROR [as 别名]
def to_http_response(self):
return {
'payload': self.reply.get('content', ''),
'status': self.reply.get('status', httplib.INTERNAL_SERVER_ERROR)
}