本文整理汇总了Python中http.client.UNAUTHORIZED属性的典型用法代码示例。如果您正苦于以下问题:Python client.UNAUTHORIZED属性的具体用法?Python client.UNAUTHORIZED怎么用?Python client.UNAUTHORIZED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类http.client
的用法示例。
在下文中一共展示了client.UNAUTHORIZED属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def __call__(self, callback):
def wrapper(*args, **kwargs):
if not is_local_request():
self._logger.info('Dropping request with bad Host header.')
abort(httplib.UNAUTHORIZED,
'Unauthorized, received request from non-local Host.')
return
if not self.is_request_authenticated():
self._logger.info('Dropping request with bad HMAC.')
abort(httplib.UNAUTHORIZED, 'Unauthorized, received bad HMAC.')
return
body = callback(*args, **kwargs)
self.sign_response_headers(response.headers, body)
return body
return wrapper
示例2: download_pdf
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def download_pdf(self, qbbo, item_id):
if self.session is None:
raise exceptions.QuickbooksException('No session')
url = "{0}/company/{1}/{2}/{3}/pdf".format(
self.api_url, self.company_id, qbbo.lower(), item_id)
headers = {
'Content-Type': 'application/pdf',
'Accept': 'application/pdf, application/json',
'User-Agent': 'python-quickbooks V3 library'
}
response = self.process_request("GET", url, headers=headers)
if response.status_code != httplib.OK:
if response.status_code == httplib.UNAUTHORIZED:
# Note that auth errors have different result structure which can't be parsed by handle_exceptions()
raise exceptions.AuthorizationException("Application authentication failed", detail=response.text)
try:
result = response.json()
except:
raise exceptions.QuickbooksException("Error reading json response: {0}".format(response.text), 10000)
self.handle_exceptions(result["Fault"])
else:
return response.content
示例3: test_missing_credentials
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def test_missing_credentials(self):
self._enable_basic_auth(self.default_username, self.default_password)
resp = self.client.get('/')
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
示例4: test_incorrect_credentials
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def test_incorrect_credentials(self):
self._enable_basic_auth(self.default_username, self.default_password)
headers = self._create_auth_headers(self.default_username, 'wrongpass')
resp = self.client.get('/', headers=headers)
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
示例5: test_incorrect_remote_address
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def test_incorrect_remote_address(self):
r = PsDashRunner({'PSDASH_ALLOWED_REMOTE_ADDRESSES': '127.0.0.1'})
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '10.0.0.1'})
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
示例6: test_multiple_remote_addresses
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def test_multiple_remote_addresses(self):
r = PsDashRunner({'PSDASH_ALLOWED_REMOTE_ADDRESSES': '127.0.0.1, 10.0.0.1'})
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '10.0.0.1'})
self.assertEqual(resp.status_code, httplib.OK)
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '127.0.0.1'})
self.assertEqual(resp.status_code, httplib.OK)
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '10.124.0.1'})
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
示例7: test_multiple_remote_addresses_using_list
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [as 别名]
def test_multiple_remote_addresses_using_list(self):
r = PsDashRunner({'PSDASH_ALLOWED_REMOTE_ADDRESSES': ['127.0.0.1', '10.0.0.1']})
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '10.0.0.1'})
self.assertEqual(resp.status_code, httplib.OK)
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '127.0.0.1'})
self.assertEqual(resp.status_code, httplib.OK)
resp = r.app.test_client().get('/', environ_overrides={'REMOTE_ADDR': '10.124.0.1'})
self.assertEqual(resp.status_code, httplib.UNAUTHORIZED)
示例8: raise_for_response
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import UNAUTHORIZED [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)