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


Python http_client.OK属性代码示例

本文整理汇总了Python中six.moves.http_client.OK属性的典型用法代码示例。如果您正苦于以下问题:Python http_client.OK属性的具体用法?Python http_client.OK怎么用?Python http_client.OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在six.moves.http_client的用法示例。


在下文中一共展示了http_client.OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def get(self, handler, *args, **kwargs):
        f = StringIO()
        for timestamp, predictions in handler.server.server.events_queue:
            data = {
                'timestamp': '{:%Y-%m-%d %H:%M:%S}'.format(timestamp),
                'predictions': predictions
            }
            f.writelines(self.render_template('event.html', **data))

        response = f.getvalue()
        f.close()

        handler.send_response(http_client.OK)
        handler.send_header('Content-type', 'text/html')
        handler.end_headers()
        handler.wfile.write(response.encode()) 
开发者ID:devicehive,项目名称:devicehive-audio-analysis,代码行数:18,代码来源:controllers.py

示例2: get

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def get(self, handler, *args, **kwargs):
        handler.send_response(http_client.OK)
        c_type = 'multipart/x-mixed-replace; boundary=--mjpegboundary'
        handler.send_header('Content-Type', c_type)
        handler.end_headers()
        prev = None
        while handler.server.server.is_running:
            data, frame_id = handler.server.server.get_frame()
            if data is not None and frame_id != prev:
                prev = frame_id
                handler.wfile.write(b'--mjpegboundary\r\n')
                handler.send_header('Content-type', 'image/jpeg')
                handler.send_header('Content-length', str(len(data)))
                handler.end_headers()
                handler.wfile.write(data)
            else:
                time.sleep(0.025) 
开发者ID:devicehive,项目名称:devicehive-video-analysis,代码行数:19,代码来源:controllers.py

示例3: do_GET

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def do_GET(self):
            """
            Handle a ping request
            """
            if not self.path.endswith("/"): self.path += "/"
            if self.path == "/ping/":
                msg = "pong".encode("UTF-8")

                self.send_response(HTTPStatus.OK)
                self.send_header("Content-Type", "text/application")
                self.send_header("Content-Length", len(msg))
                self.end_headers()
                self.wfile.write(msg)
            else:
                self.send_response(HTTPStatus.BAD_REQUEST)
                self.end_headers() 
开发者ID:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:18,代码来源:annotator.py

示例4: _test_get_run_by_id

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def _test_get_run_by_id(self):
        response = self.app.get('/runs/1234')
        self.assertEqual(http_client.NOT_FOUND, response.status_code)

        pb = 'tests/fixtures/playbooks/hello_world.yml'
        response = self.app.post(
            '/runs',
            data=json.dumps(dict(playbook_path=pb,
                                 inventory_file='localhosti,',
                                 options={'connection': 'local'})),
            content_type='application/json')
        res_dict = json.loads(response.data)
        run_id = res_dict['id']
        self.assertEqual(http_client.CREATED, response.status_code)
        response = self.app.get('/runs/{}'.format(run_id))
        self.assertEqual(http_client.OK, response.status_code)
        self._wait_for_run_complete(run_id) 
开发者ID:vmware-archive,项目名称:column,代码行数:19,代码来源:test_run.py

示例5: login

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def login(self, username, password):
        """Log in to Betfair. Sets `session_token` if successful.

        :param str username: Username
        :param str password: Password
        :raises: BetfairLoginError
        """
        response = self.session.post(
            os.path.join(self.identity_url, 'certlogin'),
            cert=self.cert_file,
            data=urllib.urlencode({
                'username': username,
                'password': password,
            }),
            headers={
                'X-Application': self.app_key,
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            timeout=self.timeout,
        )
        utils.check_status_code(response, [httplib.OK])
        data = response.json()
        if data.get('loginStatus') != 'SUCCESS':
            raise exceptions.LoginError(response, data)
        self.session_token = data['sessionToken'] 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:27,代码来源:betfair.py

示例6: test_request_refresh

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_request_refresh(self):
        credentials = mock.Mock(wraps=CredentialsStub())
        final_response = make_response(status=http_client.OK)
        # First request will 401, second request will succeed.
        adapter = AdapterStub(
            [make_response(status=http_client.UNAUTHORIZED), final_response]
        )

        authed_session = google.auth.transport.requests.AuthorizedSession(
            credentials, refresh_timeout=60
        )
        authed_session.mount(self.TEST_URL, adapter)

        result = authed_session.request("GET", self.TEST_URL)

        assert result == final_response
        assert credentials.before_request.call_count == 2
        assert credentials.refresh.called
        assert len(adapter.requests) == 2

        assert adapter.requests[0].url == self.TEST_URL
        assert adapter.requests[0].headers["authorization"] == "token"

        assert adapter.requests[1].url == self.TEST_URL
        assert adapter.requests[1].headers["authorization"] == "token1" 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:27,代码来源:test_requests.py

示例7: test_request_max_allowed_time_timeout_error

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_request_max_allowed_time_timeout_error(self, frozen_time):
        tick_one_second = functools.partial(
            frozen_time.tick, delta=datetime.timedelta(seconds=1.0)
        )

        credentials = mock.Mock(
            wraps=TimeTickCredentialsStub(time_tick=tick_one_second)
        )
        adapter = TimeTickAdapterStub(
            time_tick=tick_one_second, responses=[make_response(status=http_client.OK)]
        )

        authed_session = google.auth.transport.requests.AuthorizedSession(credentials)
        authed_session.mount(self.TEST_URL, adapter)

        # Because a request takes a full mocked second, max_allowed_time shorter
        # than that will cause a timeout error.
        with pytest.raises(requests.exceptions.Timeout):
            authed_session.request("GET", self.TEST_URL, max_allowed_time=0.9) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:21,代码来源:test_requests.py

示例8: test_request_max_allowed_time_w_transport_timeout_no_error

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_request_max_allowed_time_w_transport_timeout_no_error(self, frozen_time):
        tick_one_second = functools.partial(
            frozen_time.tick, delta=datetime.timedelta(seconds=1.0)
        )

        credentials = mock.Mock(
            wraps=TimeTickCredentialsStub(time_tick=tick_one_second)
        )
        adapter = TimeTickAdapterStub(
            time_tick=tick_one_second,
            responses=[
                make_response(status=http_client.UNAUTHORIZED),
                make_response(status=http_client.OK),
            ],
        )

        authed_session = google.auth.transport.requests.AuthorizedSession(credentials)
        authed_session.mount(self.TEST_URL, adapter)

        # A short configured transport timeout does not affect max_allowed_time.
        # The latter is not adjusted to it and is only concerned with the actual
        # execution time. The call below should thus not raise a timeout error.
        authed_session.request("GET", self.TEST_URL, timeout=0.5, max_allowed_time=3.1) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:25,代码来源:test_requests.py

示例9: test_urlopen_refresh

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_urlopen_refresh(self):
        credentials = mock.Mock(wraps=CredentialsStub())
        final_response = ResponseStub(status=http_client.OK)
        # First request will 401, second request will succeed.
        http = HttpStub([ResponseStub(status=http_client.UNAUTHORIZED), final_response])

        authed_http = google.auth.transport.urllib3.AuthorizedHttp(
            credentials, http=http
        )

        authed_http = authed_http.urlopen("GET", "http://example.com")

        assert authed_http == final_response
        assert credentials.before_request.call_count == 2
        assert credentials.refresh.called
        assert http.requests == [
            ("GET", self.TEST_URL, None, {"authorization": "token"}, {}),
            ("GET", self.TEST_URL, None, {"authorization": "token1"}, {}),
        ] 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:21,代码来源:test_urllib3.py

示例10: make_request

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def make_request(
        self,
        data,
        status=http_client.OK,
        headers=None,
        side_effect=None,
        use_data_bytes=True,
    ):
        response = mock.create_autospec(transport.Response, instance=False)
        response.status = status
        response.data = _helpers.to_bytes(data) if use_data_bytes else data
        response.headers = headers or {}

        request = mock.create_autospec(transport.Request, instance=False)
        request.side_effect = side_effect
        request.return_value = response

        return request 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:20,代码来源:test_impersonated_credentials.py

示例11: test_refresh_failure_malformed_expire_time

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_refresh_failure_malformed_expire_time(self, mock_donor_credentials):
        credentials = self.make_credentials(lifetime=None)
        token = "token"

        expire_time = (_helpers.utcnow() + datetime.timedelta(seconds=500)).isoformat(
            "T"
        )
        response_body = {"accessToken": token, "expireTime": expire_time}

        request = self.make_request(
            data=json.dumps(response_body), status=http_client.OK
        )

        with pytest.raises(exceptions.RefreshError) as excinfo:
            credentials.refresh(request)

        assert excinfo.match(impersonated_credentials._REFRESH_ERROR)

        assert not credentials.valid
        assert credentials.expired 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:test_impersonated_credentials.py

示例12: test_sign_bytes

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def test_sign_bytes(self, mock_donor_credentials, mock_authorizedsession_sign):
        credentials = self.make_credentials(lifetime=None)
        token = "token"

        expire_time = (
            _helpers.utcnow().replace(microsecond=0) + datetime.timedelta(seconds=500)
        ).isoformat("T") + "Z"
        token_response_body = {"accessToken": token, "expireTime": expire_time}

        response = mock.create_autospec(transport.Response, instance=False)
        response.status = http_client.OK
        response.data = _helpers.to_bytes(json.dumps(token_response_body))

        request = mock.create_autospec(transport.Request, instance=False)
        request.return_value = response

        credentials.refresh(request)

        assert credentials.valid
        assert not credentials.expired

        signature = credentials.sign_bytes(b"signed bytes")
        assert signature == b"signature" 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:25,代码来源:test_impersonated_credentials.py

示例13: _make_signing_request

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def _make_signing_request(self, message):
        """Makes a request to the API signBlob API."""
        message = _helpers.to_bytes(message)

        method = "POST"
        url = _SIGN_BLOB_URI.format(self._service_account_email)
        headers = {}
        body = json.dumps(
            {"payload": base64.b64encode(message).decode("utf-8")}
        ).encode("utf-8")

        self._credentials.before_request(self._request, method, url, headers)
        response = self._request(url=url, method=method, body=body, headers=headers)

        if response.status != http_client.OK:
            raise exceptions.TransportError(
                "Error calling the IAM signBytes API: {}".format(response.data)
            )

        return json.loads(response.data.decode("utf-8")) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:22,代码来源:iam.py

示例14: _fetch_certs

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def _fetch_certs(request, certs_url):
    """Fetches certificates.

    Google-style cerificate endpoints return JSON in the format of
    ``{'key id': 'x509 certificate'}``.

    Args:
        request (google.auth.transport.Request): The object used to make
            HTTP requests.
        certs_url (str): The certificate endpoint URL.

    Returns:
        Mapping[str, str]: A mapping of public key ID to x.509 certificate
            data.
    """
    response = request(certs_url, method="GET")

    if response.status != http_client.OK:
        raise exceptions.TransportError(
            "Could not fetch certificates at {}".format(certs_url)
        )

    return json.loads(response.data.decode("utf-8")) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:25,代码来源:id_token.py

示例15: do_GET

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import OK [as 别名]
def do_GET(self):
        """Handle a GET request.

        Parses the query parameters and prints a message
        if the flow has completed. Note that we can't detect
        if an error occurred.
        """
        self.send_response(http_client.OK)
        self.send_header("Content-type", "text/html")
        self.end_headers()
        query = self.path.split('?', 1)[-1]
        query = dict(urllib.parse.parse_qsl(query))
        self.server.query_params = query
        self.wfile.write(
            b"<html><head><title>Authentication Status</title></head>")
        self.wfile.write(
            b"<body><p>The authentication flow has completed.</p>")
        self.wfile.write(b"</body></html>") 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:20,代码来源:tools.py


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