当前位置: 首页>>代码示例>>Python>>正文


Python client.UNAUTHORIZED属性代码示例

本文整理汇总了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 
开发者ID:vheon,项目名称:JediHTTP,代码行数:19,代码来源:hmac_plugin.py

示例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 
开发者ID:ej2,项目名称:python-quickbooks,代码行数:31,代码来源:client.py

示例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) 
开发者ID:Jahaja,项目名称:psdash,代码行数:6,代码来源:test_web.py

示例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) 
开发者ID:Jahaja,项目名称:psdash,代码行数:9,代码来源:test_web.py

示例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) 
开发者ID:Jahaja,项目名称:psdash,代码行数:6,代码来源:test_web.py

示例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) 
开发者ID:Jahaja,项目名称:psdash,代码行数:13,代码来源:test_web.py

示例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) 
开发者ID:Jahaja,项目名称:psdash,代码行数:13,代码来源:test_web.py

示例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) 
开发者ID:openstack,项目名称:sushy,代码行数:17,代码来源:exceptions.py


注:本文中的http.client.UNAUTHORIZED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。