Python httplib.ACCEPTED Examples
The following are 10
code examples of httplib.ACCEPTED().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
httplib
, or try the search function
.
Example #1
Source File: test_entities.py From nailgun with GNU General Public License v3.0 | 6 votes |
def test_accepted_v1(self): """Give the response an HTTP "ACCEPTED" status code. Call ``_handle_response`` twice: * Do not pass the ``synchronous`` argument. * Pass ``synchronous=False``. """ response = mock.Mock() response.status_code = ACCEPTED response.headers = {'content-type': 'application/json'} for args in [response, 'foo'], [response, 'foo', False]: self.assertEqual( entities._handle_response(*args), response.json.return_value, ) self.assertEqual( response.mock_calls, [mock.call.raise_for_status(), mock.call.json()], ) response.reset_mock()
Example #2
Source File: http.py From suds with GNU Lesser General Public License v3.0 | 6 votes |
def send(self, request): url = self.__get_request_url_for_urllib(request) msg = request.message headers = request.headers try: u2request = urllib2.Request(url, msg, headers) self.addcookies(u2request) self.proxy = self.options.proxy request.headers.update(u2request.headers) log.debug('sending:\n%s', request) fp = self.u2open(u2request, timeout=request.timeout) self.getcookies(fp, u2request) headers = fp.headers if sys.version_info < (3, 0): headers = headers.dict reply = Reply(httplib.OK, headers, fp.read()) log.debug('received:\n%s', reply) return reply except urllib2.HTTPError as e: if e.code not in (httplib.ACCEPTED, httplib.NO_CONTENT): raise TransportError(e.msg, e.code, e.fp)
Example #3
Source File: proxy.py From ryu with Apache License 2.0 | 5 votes |
def _do_request(address, path): conn = httplib.HTTPConnection(address) conn.request('GET', path) res = conn.getresponse() if res.status in (httplib.OK, httplib.CREATED, httplib.ACCEPTED, httplib.NO_CONTENT): return res raise httplib.HTTPException( res, 'code %d reason %s' % (res.status, res.reason), res.getheaders(), res.read())
Example #4
Source File: test_entities.py From nailgun with GNU General Public License v3.0 | 5 votes |
def test_accepted_v2(self): """Give the response an HTTP "ACCEPTED" status code. Pass ``synchronous=True`` as an argument. """ response = mock.Mock() response.status_code = ACCEPTED response.json.return_value = {'id': gen_integer()} with mock.patch.object(entities, 'ForemanTask') as foreman_task: self.assertEqual( foreman_task.return_value.poll.return_value, entities._handle_response(response, 'foo', True), )
Example #5
Source File: lambda_runtime_client.py From knative-lambda-runtime with Apache License 2.0 | 5 votes |
def post_init_error(self, error_response_data): endpoint = self.init_error_endpoint self.runtime_connection.request("POST", endpoint, error_response_data) response = self.runtime_connection.getresponse() response_body = response.read() if response.status != httplib.ACCEPTED: raise LambdaRuntimeClientError(endpoint, response.status, response_body)
Example #6
Source File: lambda_runtime_client.py From knative-lambda-runtime with Apache License 2.0 | 5 votes |
def post_invocation_result(self, invoke_id, result_data): endpoint = self.response_endpoint.format(invoke_id) self.runtime_connection.request("POST", endpoint, result_data) response = self.runtime_connection.getresponse() response_body = response.read() if response.status != httplib.ACCEPTED: raise LambdaRuntimeClientError(endpoint, response.status, response_body)
Example #7
Source File: lambda_runtime_client.py From knative-lambda-runtime with Apache License 2.0 | 5 votes |
def post_invocation_error(self, invoke_id, error_response_data): endpoint = self.error_response_endpoint.format(invoke_id) self.runtime_connection.request("POST", endpoint, error_response_data) response = self.runtime_connection.getresponse() response_body = response.read() if response.status != httplib.ACCEPTED: raise LambdaRuntimeClientError(endpoint, response.status, response_body)
Example #8
Source File: KeyVaultUtil.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def get_access_token(self, KeyVaultResourceName, AuthorizeUri, AADClientID, AADClientCertThumbprint, AADClientSecret): if not AADClientSecret and not AADClientCertThumbprint: raise ValueError("Missing Credentials. Either AADClientSecret or AADClientCertThumbprint must be specified") if AADClientSecret and AADClientCertThumbprint: raise ValueError("Both AADClientSecret and AADClientCertThumbprint were supplied, when only one of these was expected.") if AADClientCertThumbprint: return self.get_access_token_with_certificate(KeyVaultResourceName, AuthorizeUri, AADClientID, AADClientCertThumbprint) else: # retrieve access token directly, adal library not required token_uri = AuthorizeUri + "/oauth2/token" request_content = "resource=" + urllib.quote(KeyVaultResourceName) + "&client_id=" + AADClientID + "&client_secret=" + urllib.quote(AADClientSecret) + "&grant_type=client_credentials" headers = {} http_util = HttpUtil(self.logger) result = http_util.Call(method='POST', http_uri=token_uri, data=request_content, headers=headers) self.logger.log("{0} {1}".format(result.status, result.getheaders())) result_content = result.read() if result.status != httplib.OK and result.status != httplib.ACCEPTED: self.logger.log(str(result_content)) return None http_util.connection.close() result_json = json.loads(result_content) access_token = result_json["access_token"] return access_token
Example #9
Source File: KeyVaultUtil.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def encrypt_passphrase(self, AccessToken, Passphrase, KeyVaultURL, KeyEncryptionKeyURL, AADClientID, KeyEncryptionAlgorithm, AADClientSecret): try: """ wrap our passphrase using the encryption key api ref for wrapkey: https://msdn.microsoft.com/en-us/library/azure/dn878066.aspx """ self.logger.log("encrypting the secret using key: " + KeyEncryptionKeyURL) request_content = '{"alg":"' + str(KeyEncryptionAlgorithm) + '","value":"' + str(Passphrase) + '"}' headers = {} headers["Content-Type"] = "application/json" headers["Authorization"] = "Bearer " + str(AccessToken) relative_path = KeyEncryptionKeyURL + "/wrapkey" + '?api-version=' + self.api_version http_util = HttpUtil(self.logger) result = http_util.Call(method='POST', http_uri=relative_path, data=request_content, headers=headers) result_content = result.read() self.logger.log("result_content is: {0}".format(result_content)) self.logger.log("{0} {1}".format(result.status, result.getheaders())) if result.status != httplib.OK and result.status != httplib.ACCEPTED: return None http_util.connection.close() result_json = json.loads(result_content) secret_value = result_json[u'value'] return secret_value except Exception as e: self.logger.log("Failed to encrypt_passphrase with error: {0}, stack trace: %s".format(e, traceback.format_exc())) return None
Example #10
Source File: KeyVaultUtil.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def create_secret(self, AccessToken, KeyVaultURL, secret_value, KeyEncryptionAlgorithm, DiskEncryptionKeyFileName): """ create secret api https://msdn.microsoft.com/en-us/library/azure/dn903618.aspx https://mykeyvault.vault.azure.net/secrets/{secret-name}?api-version={api-version} """ try: secret_name = str(uuid.uuid4()) secret_keyvault_uri = self.urljoin(KeyVaultURL, "secrets", secret_name) self.logger.log("secret_keyvault_uri is: {0} and keyvault_uri is:{1}".format(secret_keyvault_uri, KeyVaultURL)) if KeyEncryptionAlgorithm is None: request_content = '{{"value":"{0}","attributes":{{"enabled":"true"}},"tags":{{"DiskEncryptionKeyFileName":"{1}"}}}}'\ .format(str(secret_value), DiskEncryptionKeyFileName) else: request_content = '{{"value":"{0}","attributes":{{"enabled":"true"}},"tags":{{"DiskEncryptionKeyEncryptionAlgorithm":"{1}","DiskEncryptionKeyFileName":"{2}"}}}}'\ .format(str(secret_value), KeyEncryptionAlgorithm, DiskEncryptionKeyFileName) http_util = HttpUtil(self.logger) headers = {} headers["Content-Type"] = "application/json" headers["Authorization"] = "Bearer " + AccessToken result = http_util.Call(method='PUT', http_uri=secret_keyvault_uri + '?api-version=' + self.api_version, data=request_content, headers=headers) self.logger.log("{0} {1}".format(result.status, result.getheaders())) result_content = result.read() # Do NOT log the result_content. It contains the uploaded secret and we don't want that in the logs. result_json = json.loads(result_content) secret_id = result_json["id"] http_util.connection.close() if result.status != httplib.OK and result.status != httplib.ACCEPTED: self.logger.log("the result status failed.") return None return secret_id except Exception as e: self.logger.log("Failed to create_secret with error: {0}, stack trace: {1}".format(e, traceback.format_exc())) return None