本文整理汇总了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'
示例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
示例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
示例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
示例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))
示例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))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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