本文整理匯總了Python中http.client.INTERNAL_SERVER_ERROR屬性的典型用法代碼示例。如果您正苦於以下問題:Python client.INTERNAL_SERVER_ERROR屬性的具體用法?Python client.INTERNAL_SERVER_ERROR怎麽用?Python client.INTERNAL_SERVER_ERROR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類http.client
的用法示例。
在下文中一共展示了client.INTERNAL_SERVER_ERROR屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def add(self):
try:
params = self._prepare_request()
except Exception:
LOG.exception('Exception when reading CNI params.')
return '', httplib.BAD_REQUEST, self.headers
try:
vif = self.plugin.add(params)
data = jsonutils.dumps(vif.obj_to_primitive())
except exception.ResourceNotReady:
LOG.error('Error when processing addNetwork request')
return '', httplib.GATEWAY_TIMEOUT, self.headers
except Exception:
LOG.exception('Error when processing addNetwork request. CNI '
'Params: %s', params)
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
return data, httplib.ACCEPTED, self.headers
示例2: delete
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def delete(self):
try:
params = self._prepare_request()
except Exception:
LOG.exception('Exception when reading CNI params.')
return '', httplib.BAD_REQUEST, self.headers
try:
self.plugin.delete(params)
except exception.ResourceNotReady:
# NOTE(dulek): It's better to ignore this error - most of the time
# it will happen when capsule is long gone and runtime
# overzealously tries to delete it from the network.
# We cannot really do anything without VIF metadata,
# so let's just tell runtime to move along.
LOG.warning('Error when processing delNetwork request. '
'Ignoring this error, capsule is most likely gone')
return '', httplib.NO_CONTENT, self.headers
except Exception:
LOG.exception('Error when processing delNetwork request. CNI '
'Params: %s.', params)
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
return '', httplib.NO_CONTENT, self.headers
示例3: add
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def add(self):
try:
params = self._prepare_request()
except Exception:
self._check_failure()
LOG.exception('Exception when reading CNI params.')
return '', httplib.BAD_REQUEST, self.headers
try:
vif = self.plugin.add(params)
data = jsonutils.dumps(vif.obj_to_primitive())
except exceptions.ResourceNotReady:
self._check_failure()
LOG.error('Error when processing addNetwork request')
return '', httplib.GATEWAY_TIMEOUT, self.headers
except Exception:
self._check_failure()
LOG.exception('Error when processing addNetwork request. CNI '
'Params: %s', params)
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
return data, httplib.ACCEPTED, self.headers
示例4: delete
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def delete(self):
try:
params = self._prepare_request()
except Exception:
LOG.exception('Exception when reading CNI params.')
return '', httplib.BAD_REQUEST, self.headers
try:
self.plugin.delete(params)
except exceptions.ResourceNotReady:
# NOTE(dulek): It's better to ignore this error - most of the time
# it will happen when pod is long gone and CRI
# overzealously tries to delete it from the network.
# We cannot really do anything without VIF annotation,
# so let's just tell CRI to move along.
LOG.warning('Error when processing delNetwork request. '
'Ignoring this error, pod is most likely gone')
return '', httplib.NO_CONTENT, self.headers
except Exception:
self._check_failure()
LOG.exception('Error when processing delNetwork request. CNI '
'Params: %s.', params)
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
return '', httplib.NO_CONTENT, self.headers
示例5: csp_middleware
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def csp_middleware(get_response):
def middleware(request):
nonce_func = partial(make_csp_nonce, request)
request.csp_nonce = SimpleLazyObject(nonce_func)
response = get_response(request)
if CSP_HEADER in response:
# header already present (HOW ???)
return response
if response.status_code in (INTERNAL_SERVER_ERROR, NOT_FOUND) and settings.DEBUG:
# no policies in debug views
return response
response[CSP_HEADER] = build_csp_header(request)
return response
return middleware
示例6: test_client_bad_request_with_parameters
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client 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))
示例7: readiness_status
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def readiness_status(self):
data = 'ok'
if CONF.kubernetes.vif_pool_driver != 'noop':
if not os.path.exists('/tmp/pools_loaded'):
error_message = 'Ports not loaded into the pools.'
LOG.error(error_message)
return error_message, httplib.NOT_FOUND, self.headers
k8s_conn = self.verify_k8s_connection()
if not k8s_conn:
error_message = 'Error when processing k8s healthz request.'
LOG.error(error_message)
return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers
try:
self.verify_keystone_connection()
except Exception as ex:
error_message = ('Error when creating a Keystone session and '
'getting a token: %s.' % ex)
LOG.exception(error_message)
return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers
try:
if not self._components_ready():
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
except Exception as ex:
error_message = ('Error when processing neutron request %s' % ex)
LOG.exception(error_message)
return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers
LOG.info('Kuryr Controller readiness verified.')
return data, httplib.OK, self.headers
示例8: liveness_status
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def liveness_status(self):
data = 'ok'
for component in self._registry:
if not component.is_alive():
LOG.debug('Kuryr Controller not healthy.')
return '', httplib.INTERNAL_SERVER_ERROR, self.headers
LOG.debug('Kuryr Controller Liveness verified.')
return data, httplib.OK, self.headers
示例9: readiness_status
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def readiness_status(self):
data = 'ok'
k8s_conn = self.verify_k8s_connection()
if not _has_cap(CAP_NET_ADMIN, EFFECTIVE_CAPS):
error_message = 'NET_ADMIN capabilities not present.'
LOG.error(error_message)
return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers
if not k8s_conn:
error_message = 'Error when processing k8s healthz request.'
LOG.error(error_message)
return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers
LOG.info('CNI driver readiness verified.')
return data, httplib.OK, self.headers
示例10: raise_for_response
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def raise_for_response(method, url, response):
"""Raise a correct error class, if needed."""
if response.status_code < http_client.BAD_REQUEST:
return
elif response.status_code == http_client.NOT_FOUND:
raise ResourceNotFoundError(method, url, response)
elif response.status_code == http_client.BAD_REQUEST:
raise BadRequestError(method, url, response)
elif response.status_code in (http_client.UNAUTHORIZED,
http_client.FORBIDDEN):
raise AccessError(method, url, response)
elif response.status_code >= http_client.INTERNAL_SERVER_ERROR:
raise ServerSideError(method, url, response)
else:
raise HTTPError(method, url, response)
示例11: test_server_error
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def test_server_error(self):
self.request.return_value.status_code = (
http_client.INTERNAL_SERVER_ERROR)
self.request.return_value.json.side_effect = ValueError('no json')
with self.assertRaisesRegex(exceptions.ServerSideError,
'unknown error') as cm:
self.conn._op('GET', 'http://foo.bar')
exc = cm.exception
self.assertEqual(http_client.INTERNAL_SERVER_ERROR, exc.status_code)
示例12: process_web_request
# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import INTERNAL_SERVER_ERROR [as 別名]
def process_web_request(self, request, path, params, fragment):
"""Implements CommandHandler."""
options = dict(get_global_options())
options.update(params)
if str(params.get('clear_all')).lower() != 'true':
stackdriver = stackdriver_service.make_service(options)
audit_results = stackdriver_descriptors.AuditResults(stackdriver)
descriptor_list = audit_results.descriptor_map.values()
descriptor_html = '\n<li> '.join(item['type'] for item in descriptor_list)
html = textwrap.dedent("""\
Clearing descriptors requires query parameter
<code>clear_all=true</code>.
<p/>
Here are the {count} custom descriptors:
<ul>
<li>{descriptors}
</ul>
<p/>
<a href="{path}?clear_all=true">Yes, delete everything!</a>
""".format(count=len(descriptor_list),
descriptors=descriptor_html,
path=path))
html_doc = http_server.build_html_document(
html, title='Missing Parameters')
request.respond(
400, {'ContentType': 'text/html'}, html_doc)
return
audit_results = self.__do_clear(options)
response_code = (httplib.OK if audit_results.obsoleted_count == 0
else httplib.INTERNAL_SERVER_ERROR)
headers = {'Content-Type': 'text/plain'}
body = audit_results_to_output(
audit_results, "No custom descriptors to delete.")
request.respond(response_code, headers, body)