當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。