本文整理汇总了Python中httplib.responses方法的典型用法代码示例。如果您正苦于以下问题:Python httplib.responses方法的具体用法?Python httplib.responses怎么用?Python httplib.responses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib
的用法示例。
在下文中一共展示了httplib.responses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serve_image
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def serve_image(self, environ, start_response):
"""Dynamically serve an image from blobstore."""
blobkey, options = self._parse_path(environ['PATH_INFO'])
# Make sure that the blob URL has been registered by
# calling get_serving_url
key = datastore.Key.from_path(_BLOB_SERVING_URL_KIND, blobkey, namespace='')
try:
datastore.Get(key)
except datastore_errors.EntityNotFoundError:
logging.error('The blobkey %s has not registered for image '
'serving. Please ensure get_serving_url is '
'called before attempting to serve blobs.', blobkey)
start_response('404 %s' % httplib.responses[404], [])
return []
image, mime_type = self._transform_image(blobkey, options)
start_response('200 OK', [
('Content-Type', mime_type),
('Cache-Control', 'public, max-age=600, no-transform')])
return [image]
示例2: __write_error
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __write_error(self, status_code, error_message=None):
"""Return the HTTP status line and body for a given error code and message.
Args:
status_code: HTTP status code to be returned.
error_message: Error message to be returned.
Returns:
Tuple (http_status, body):
http_status: HTTP status line, e.g. 200 OK.
body: Body of the HTTP request.
"""
if error_message is None:
error_message = httplib.responses[status_code]
status = '%d %s' % (status_code, httplib.responses[status_code])
message = EndpointsErrorMessage(
state=EndpointsErrorMessage.State.APPLICATION_ERROR,
error_message=error_message)
return status, self.__PROTOJSON.encode_message(message)
示例3: write_headers
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def write_headers(self, start_line, headers, chunk=None, callback=None):
"""Write an HTTP header block.
:arg start_line: a `.RequestStartLine` or `.ResponseStartLine`.
:arg headers: a `.HTTPHeaders` instance.
:arg chunk: the first (optional) chunk of data. This is an optimization
so that small responses can be written in the same call as their
headers.
:arg callback: a callback to be run when the write is complete.
The ``version`` field of ``start_line`` is ignored.
Returns a `.Future` if no callback is given.
.. deprecated:: 5.1
The ``callback`` argument is deprecated and will be removed
in Tornado 6.0.
"""
raise NotImplementedError()
示例4: set_label
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def set_label(self, item,label, changed):
if self.encode_password is None:
return
if not changed:
return
try:
bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
params = json.dumps(bundle)
connection = httplib.HTTPConnection(self.target_host)
connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})
response = connection.getresponse()
if response.reason == httplib.responses[httplib.NOT_FOUND]:
return
response = json.loads(response.read())
except socket.gaierror as e:
print_error('Error connecting to service: %s ' % e)
return False
示例5: _test_connectivity
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _test_connectivity(self, param):
"""
Called when the user depresses the test connectivity button on the Phantom UI.
Use a basic query to determine if the IP address, username and password is correct,
curl -k -u admin:redacted -X GET https://192.0.2.1/mgmt/tm/ltm/
"""
self.debug_print("%s TEST_CONNECTIVITY %s" % (F5_Connector.BANNER, param))
config = self.get_config()
host = config.get("device")
F5 = iControl.BIG_IP(host=host,
username=config.get("username"),
password=config.get("password"),
uri="/mgmt/tm/sys/software/image",
method="GET")
msg = "test connectivity to %s status_code: " % host
if F5.genericGET():
# True is success
return self.set_status_save_progress(phantom.APP_SUCCESS, msg + "%s %s" % (F5.status_code, httplib.responses[F5.status_code]))
else:
# None or False, is a failure based on incorrect IP address, username, passords
return self.set_status_save_progress(phantom.APP_ERROR, msg + "%s %s" % (F5.status_code, F5.response))
示例6: _test_connectivity
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _test_connectivity(self, param, LADS):
"""
Called when the user depresses the test connectivity button on the Phantom UI.
This query returns a list of configured applications
https://api.a10networks.com/api/v2/applications
"""
self.debug_print("%s _test_connectivity %s" % (A10_LADS_Connector.BANNER, param))
msg = "test connectivity to %s status_code: " % (LADS.dashboard)
if LADS.genericGET(uri="/api/v2/applications"):
# True is success
return self.set_status_save_progress(phantom.APP_SUCCESS, msg + "%s %s apps: %s" %
(LADS.status_code, httplib.responses[LADS.status_code], LADS.get_names(LADS.response)))
else:
# None or False, is a failure based on incorrect IP address, username, passords
return self.set_status_save_progress(phantom.APP_ERROR, msg + "%s %s" % (LADS.status_code, LADS.response))
示例7: _handle_request_exception
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _handle_request_exception(self, e):
if isinstance(e, HTTPError):
if e.log_message:
format = "%d %s: " + e.log_message
args = [e.status_code, self._request_summary()] + list(e.args)
#logging.warning(format, *args)
ht.logger.warning(format, *args)
if e.status_code not in httplib.responses:
#logging.error("Bad HTTP status code: %d", e.status_code)
ht.logger.error("Bad HTTP status code: %d", e.status_code)
self.send_error(500, exc_info=sys.exc_info())
else:
self.send_error(e.status_code, exc_info=sys.exc_info())
else:
#logging.error("Uncaught exception %s\n%r", self._request_summary(),
# self.request, exc_info=True)
ht.logger.error("Uncaught exception %s\n%r", self._request_summary(),
self.request, exc_info=True)
self.send_error(500, exc_info=sys.exc_info())
示例8: _in_progress_response
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _in_progress_response(start_response, ntlm_data=None,
client_id=None, cookie_name=None):
status = "401 %s" % httplib.responses[401]
content = "More data needed..."
headers = [("Content-Type", "text/plain"),
("Content-Length", "%d" % len(content))]
if ntlm_data is None:
www_auth_value = "NTLM"
else:
enc_ntlm_data = ntlm_data.encode("base64")
www_auth_value = ("NTLM %s"
% enc_ntlm_data.strip().replace("\n", ""))
if client_id is not None:
# MUST occur when ntlm_data is None, can still occur otherwise
headers.append(("Set-Cookie", "%s=%s" % (cookie_name, client_id)))
headers.append(("WWW-Authenticate", www_auth_value))
start_response(status, headers)
return [content]
示例9: test_handle_build_err
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_handle_build_err(self):
# Special-cased above for testing.
self.res.request = FakeHttpRequest('POST')
settings.DEBUG = False
self.addCleanup(setattr, settings, 'DEBUG', True)
resp = self.res.handle('detail')
self.assertEqual(resp['Content-Type'], 'application/json')
self.assertEqual(resp.status_code, 500)
self.assertEqual(resp.reason_phrase.title(), responses[500])
self.assertEqual(json.loads(resp.content.decode('utf-8')), {
'error': {
'code': 'random-crazy',
'message': 'This is a random & crazy exception.',
}
})
示例10: _error_response
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _error_response(self, environ, start_response, status):
start_response('%d %s' % (status, httplib.responses[status]), [])
return []
示例11: __call__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __call__(self, environ, start_response):
with self._lock:
app = self._app
error = self._error
if app:
return app(environ, start_response)
else:
start_response('%d %s' % (error, httplib.responses[error]), [])
return []
示例12: test_not_get
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_not_get(self):
"""Tests POSTing to a url."""
self._environ['REQUEST_METHOD'] = 'POST'
self.assertResponse('405 %s' % httplib.responses[405], [], '', self.app,
self._environ)
示例13: test_key_not_found
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_key_not_found(self):
"""Tests an image request for a key that doesn't exist."""
self.expect_datatore_lookup('SomeBlobKey', False)
self.mox.ReplayAll()
self.assertResponse('404 %s' % httplib.responses[404], [], '', self.app,
self._environ)
示例14: test_invalid_url
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_invalid_url(self):
"""Tests an image request with an invalid path."""
self._environ['PATH_INFO'] = '/_ah/img/'
self.mox.ReplayAll()
self.assertResponse('400 %s' % httplib.responses[400], [], '', self.app,
self._environ)
示例15: __call__
# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __call__(self, environ, start_response):
if environ['REQUEST_METHOD'] != 'GET':
start_response('405 %s' % httplib.responses[405], [])
return []
try:
return self.serve_image(environ, start_response)
except InvalidRequestError:
start_response('400 %s' % httplib.responses[400], [])
return []