當前位置: 首頁>>代碼示例>>Python>>正文


Python client.OK屬性代碼示例

本文整理匯總了Python中http.client.OK屬性的典型用法代碼示例。如果您正苦於以下問題:Python client.OK屬性的具體用法?Python client.OK怎麽用?Python client.OK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在http.client的用法示例。


在下文中一共展示了client.OK屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _logout

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def _logout(self):
        """Posts a logout request to the server.

            Returns:
                str     -   response string from server upon logout success

        """
        flag, response = self.make_request('POST', self._commcell_object._services['LOGOUT'])

        if flag:
            self._commcell_object._headers['Authtoken'] = None

            if response.status_code == httplib.OK:
                return response.text
            else:
                return 'Failed to logout the user'
        else:
            return 'User already logged out' 
開發者ID:CommvaultEngg,項目名稱:cvpysdk,代碼行數:20,代碼來源:cvpysdk.py

示例2: autoscroll

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def autoscroll():
    response = {"result": "success"}
    status_code = http_status.OK

    data = request.get_json()
    if data is None:
        data = request.form
    try:
        api_queue.put(Action("autoscroll", (data["is_enabled"], float(data["interval"]))))
    except KeyError:
        response = {"result": "KeyError", "error": "keys is_enabled and interval not posted."}
        status_code = http_status.UNPROCESSABLE_ENTITY
    except ValueError:
        response = {"result": "ValueError", "error": "invalid data type(s)."}
        status_code = http_status.UNPROCESSABLE_ENTITY

    return jsonify(response), status_code 
開發者ID:pimoroni,項目名稱:scroll-phat-hd,代碼行數:19,代碼來源:http.py

示例3: scroll

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def scroll():
    response = {"result": "success"}
    status_code = http_status.OK

    data = request.get_json()
    if data is None:
        data = request.form
    try:
        api_queue.put(Action("scroll", (int(data["x"]), int(data["y"]))))
    except KeyError:
        response = {"result": "KeyError", "error": "keys x and y not posted."}
        status_code = http_status.UNPROCESSABLE_ENTITY
    except ValueError:
        response = {"result": "ValueError", "error": "invalid integer."}
        status_code = http_status.UNPROCESSABLE_ENTITY

    return jsonify(response), status_code 
開發者ID:pimoroni,項目名稱:scroll-phat-hd,代碼行數:19,代碼來源:http.py

示例4: flip

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def flip():
    response = {"result": "success"}
    status_code = http_status.OK

    data = request.get_json()
    if data is None:
        data = request.form
    try:
        api_queue.put(Action("flip", (bool(data["x"]), bool(data["y"]))))
    except TypeError:
        response = {"result": "TypeError", "error": "Could not cast data correctly. Both `x` and `y` must be set to true or false."}
        status_code = http_status.UNPROCESSABLE_ENTITY
    except KeyError:
        response = {"result": "KeyError", "error": "Could not cast data correctly. Both `x` and `y` must be in the posted json data."}
        status_code = http_status.UNPROCESSABLE_ENTITY

    return jsonify(response), status_code 
開發者ID:pimoroni,項目名稱:scroll-phat-hd,代碼行數:19,代碼來源:http.py

示例5: test_client_request_with_parameters

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_client_request_with_parameters(jedihttp):
    filepath = utils.fixture_filepath('goto.py')
    request_data = {
        'source': read_file(filepath),
        'line': 10,
        'col': 3,
        '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.OK))

    hmachelper = hmaclib.JediHTTPHmacHelper(SECRET)
    assert_that(hmachelper.is_response_authenticated(response.headers,
                                                     response.content)) 
開發者ID:vheon,項目名稱:JediHTTP,代碼行數:21,代碼來源:end_to_end_test.py

示例6: test_client_python3_specific_syntax_completion

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_client_python3_specific_syntax_completion(jedihttp):
    filepath = utils.fixture_filepath('py3.py')
    request_data = {
        'source': read_file(filepath),
        'line': 19,
        'col': 11,
        'source_path': filepath
    }

    response = requests.post('http://127.0.0.1:{0}/completions'.format(PORT),
                             json=request_data,
                             auth=HmacAuth(SECRET))

    assert_that(response.status_code, equal_to(httplib.OK))

    hmachelper = hmaclib.JediHTTPHmacHelper(SECRET)
    assert_that(hmachelper.is_response_authenticated(response.headers,
                                                     response.content)) 
開發者ID:vheon,項目名稱:JediHTTP,代碼行數:20,代碼來源:end_to_end_test.py

示例7: perform

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def perform(self, connection):
        assert self.url is not None

        self.log_request(self.method, self.url)
        connection.request(self.method, self.url)

        response = connection.getresponse()
        if response.status != http.OK:
            raise RuntimeError(
                "HTTP error performing {} request: {} {}".format(
                    self.service, response.status, response.reason
                )
            )

        data = response.read().decode("utf-8")
        return self.handle_response(data) 
開發者ID:erijo,項目名稱:sunnyportal-py,代碼行數:18,代碼來源:requests.py

示例8: test_response_headers

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_response_headers(self):
        # test response with multiple message headers with the same field name.
        text = ('HTTP/1.1 200 OK\r\n'
                'Set-Cookie: Customer="WILE_E_COYOTE"; '
                'Version="1"; Path="/acme"\r\n'
                'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";'
                ' Path="/acme"\r\n'
                '\r\n'
                'No body\r\n')
        hdr = ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"'
               ', '
               'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"')
        s = FakeSocket(text)
        r = client.HTTPResponse(s)
        r.begin()
        cookies = r.getheader("Set-Cookie")
        self.assertEqual(cookies, hdr) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:19,代碼來源:test_httplib.py

示例9: test_chunked_head

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_chunked_head(self):
        chunked_start = (
            'HTTP/1.1 200 OK\r\n'
            'Transfer-Encoding: chunked\r\n\r\n'
            'a\r\n'
            'hello world\r\n'
            '1\r\n'
            'd\r\n'
        )
        sock = FakeSocket(chunked_start + last_chunk + chunked_end)
        resp = client.HTTPResponse(sock, method="HEAD")
        resp.begin()
        self.assertEqual(resp.read(), b'')
        self.assertEqual(resp.status, 200)
        self.assertEqual(resp.reason, 'OK')
        self.assertTrue(resp.isclosed())
        self.assertFalse(resp.closed)
        resp.close()
        self.assertTrue(resp.closed) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:21,代碼來源:test_httplib.py

示例10: test_readinto_chunked_head

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_readinto_chunked_head(self):
        chunked_start = (
            'HTTP/1.1 200 OK\r\n'
            'Transfer-Encoding: chunked\r\n\r\n'
            'a\r\n'
            'hello world\r\n'
            '1\r\n'
            'd\r\n'
        )
        sock = FakeSocket(chunked_start + last_chunk + chunked_end)
        resp = client.HTTPResponse(sock, method="HEAD")
        resp.begin()
        b = bytearray(5)
        n = resp.readinto(b)
        self.assertEqual(n, 0)
        self.assertEqual(bytes(b), b'\x00'*5)
        self.assertEqual(resp.status, 200)
        self.assertEqual(resp.reason, 'OK')
        self.assertTrue(resp.isclosed())
        self.assertFalse(resp.closed)
        resp.close()
        self.assertTrue(resp.closed) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:24,代碼來源:test_httplib.py

示例11: test_delete_v6

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_delete_v6(self):
        """
        What happens if the server returns an HTTP OK status and blank only
        content?
        """
        response = mock.Mock()
        response.status_code = http_client.OK
        response.content = ' '
        with mock.patch.object(
            entity_mixins.EntityDeleteMixin,
            'delete_raw',
            return_value=response,
        ):
            with mock.patch.object(entity_mixins, '_poll_task') as poll_task:
                self.assertEqual(self.entity.delete(), None)
        self.assertEqual(poll_task.call_count, 0) 
開發者ID:SatelliteQE,項目名稱:nailgun,代碼行數:18,代碼來源:test_entity_mixins.py

示例12: request_access_token

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def request_access_token(self, auth_code):
        if self._state != auth_code.state:
            raise ValueError("Unexpected state parameter [{}] passed".format(auth_code.state))
        self._params.update({
            "code": auth_code.code,
            "code_verifier": self._code_verifier,
            "grant_type": "authorization_code",
        })
        resp = _requests.post(
            url=self._token_endpoint,
            data=self._params,
            headers=self._headers,
            allow_redirects=False
        )
        if resp.status_code != _StatusCodes.OK:
            # TODO: handle expected (?) error cases:
            #  https://auth0.com/docs/flows/guides/device-auth/call-api-device-auth#token-responses
            raise Exception('Failed to request access token with response: [{}] {}'.format(
                resp.status_code, resp.content))
        self._initialize_credentials(resp) 
開發者ID:lyft,項目名稱:flytekit,代碼行數:22,代碼來源:auth.py

示例13: refresh_access_token

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def refresh_access_token(self):
        if self._refresh_token is None:
            raise ValueError("no refresh token available with which to refresh authorization credentials")

        resp = _requests.post(
            url=self._token_endpoint,
            data={'grant_type': 'refresh_token',
                  'client_id': self._client_id,
                  'refresh_token': self._refresh_token},
            headers=self._headers,
            allow_redirects=False
        )
        if resp.status_code != _StatusCodes.OK:
            self._expired = True
            # In the absence of a successful response, assume the refresh token is expired. This should indicate
            # to the caller that the AuthorizationClient is defunct and a new one needs to be re-initialized.

            _keyring.delete_password(_keyring_service_name, _keyring_access_token_storage_key)
            _keyring.delete_password(_keyring_service_name, _keyring_refresh_token_storage_key)
            return
        self._initialize_credentials(resp) 
開發者ID:lyft,項目名稱:flytekit,代碼行數:23,代碼來源:auth.py

示例14: test_timed_out_session_re_established

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def test_timed_out_session_re_established(self):
        self.auth._session_key = 'asdf1234'
        self.auth.get_session_key.return_value = 'asdf1234'
        self.conn._auth = self.auth
        self.session = mock.Mock(spec=requests.Session)
        self.conn._session = self.session
        self.request = self.session.request
        first_response = mock.MagicMock()
        first_response.status_code = http_client.FORBIDDEN
        second_response = mock.MagicMock()
        second_response.status_code = http_client.OK
        second_response.json = {'Test': 'Testing'}
        self.request.side_effect = [first_response, second_response]
        response = self.conn._op('POST', path='fake/path', data=self.data,
                                 headers=self.headers)
        self.auth.refresh_session.assert_called_with()
        self.assertEqual(response.json, second_response.json) 
開發者ID:openstack,項目名稱:sushy,代碼行數:19,代碼來源:test_connector.py

示例15: healthy

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import OK [as 別名]
def healthy(self):
        """
        Check whether the :code:`ngrok` process has finished starting up and is in a running, healthy state.

        :return: :code:`True` if the :code:`ngrok` process is started, running, and healthy, :code:`False` otherwise.
        :rtype: bool
        """
        if self.api_url is None or \
                not self._tunnel_started or not self._client_connected:
            return False

        if not self.api_url.lower().startswith("http"):
            raise PyngrokSecurityError("URL must start with \"http\": {}".format(self.api_url))

        # Ensure the process is available for requests before registering it as healthy
        request = Request("{}/api/tunnels".format(self.api_url))
        response = urlopen(request)
        if response.getcode() != StatusCodes.OK:
            return False

        return self.proc.poll() is None and \
               self.startup_error is None 
開發者ID:alexdlaird,項目名稱:pyngrok,代碼行數:24,代碼來源:process.py


注:本文中的http.client.OK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。