本文整理汇总了Python中msrest.exceptions.HttpOperationError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.HttpOperationError方法的具体用法?Python exceptions.HttpOperationError怎么用?Python exceptions.HttpOperationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msrest.exceptions
的用法示例。
在下文中一共展示了exceptions.HttpOperationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_projects
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def list_projects(self):
"""Lists the current projects within an organization"""
url = '/_apis/projects'
# First pass without X-VSS-ForceMsaPassThrough header
response = self._list_projects_request(url)
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", response.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('Projects', response)
return deserialized
示例2: _is_project_created
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def _is_project_created(self, project_id):
"""Helper function to see the status of a project"""
url = '/' + self._organization_name + '/_apis/operations/' + project_id
query_paramters = {}
header_paramters = {}
header_paramters['Accept'] = 'application/json'
if self._user_mgr.is_msa_account():
header_paramters['X-VSS-ForceMsaPassThrough'] = 'true'
request = self._create_project_client.get(url, params=query_paramters)
response = self._create_project_client.send(request, headers=header_paramters)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('ProjectPoll', response)
return deserialized
示例3: list_regions
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def list_regions(self):
"""List what regions organizations can exist in"""
# Construct URL
url = '/_apis/hostacquisition/regions'
#construct header parameters
header_paramters = {}
header_paramters['Accept'] = 'application/json'
# Construct and send request
request = self._list_region_client.get(url, headers=header_paramters)
response = self._list_region_client.send(request)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('Regions', response)
return deserialized
示例4: run_with_retry
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def run_with_retry(fun, args, kwargs):
failures_left = max_failure_count
retry = True
backoff = initial_backoff + random.randint(1, 10)
while retry:
try:
return fun(*args, **kwargs)
except HttpOperationError as e:
resp = e.response.json()
retry = False
if "Message" in resp:
if resp["Message"].startswith("ErrorCode:ThrottlingBacklogTimeout"):
retry = True
if retry and failures_left:
failures_left = failures_left - 1
print("{} failures left before giving up".format(failures_left))
print("sleeping for {} seconds".format(backoff))
time.sleep(backoff)
backoff = backoff * 2
else:
raise e
示例5: list_pools
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def list_pools(self):
"""List what pools this project has"""
project = self._get_project_by_name(self._project_name)
# Construct URL
url = "/" + project.id + "/_apis/distributedtask/queues?actionFilter=16"
#construct header parameters
header_paramters = {}
if self._user_mgr.is_msa_account():
header_paramters['X-VSS-ForceMsaPassThrough'] = 'true'
header_paramters['Accept'] = 'application/json'
# Construct and send request
request = self._client.get(url, headers=header_paramters)
response = self._client.send(request)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('Pools', response)
return deserialized
示例6: get_user
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def get_user(self, msa=False):
# Try to get from cache
if msa is True and self._cache_msa_user is not None:
return self._cache_msa_user
if msa is False and self._cache_aad_user is not None:
return self._cache_aad_user
header_parameters = {}
header_parameters['X-VSS-ForceMsaPassThrough'] = 'true' if msa else 'false'
header_parameters['Accept'] = 'application/json'
request = self._client.get('/_apis/AzureTfs/UserContext')
response = self._client.send(request, header_parameters)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('User', response)
# Write to cache
if msa is True and self._cache_msa_user is None:
self._cache_msa_user = deserialized
if msa is False and self._cache_aad_user is None:
self._cache_aad_user = deserialized
return deserialized
示例7: validate_organization_name
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def validate_organization_name(self, organization_name):
"""Validate an organization name by checking it does not already exist and that it fits name restrictions"""
if organization_name is None:
return models.ValidateAccountName(valid=False, message="The organization_name cannot be None")
if re.search("[^0-9A-Za-z-]", organization_name):
return models.ValidateAccountName(valid=False, message="""The name supplied contains forbidden characters.
Only alphanumeric characters and dashes are allowed.
Please try another organization name.""")
#construct url
url = '/_AzureSpsAccount/ValidateAccountName'
#construct query parameters
query_paramters = {}
query_paramters['accountName'] = organization_name
#construct header parameters
header_paramters = {}
header_paramters['Accept'] = 'application/json'
request = self._client.get(url, params=query_paramters)
response = self._client.send(request, headers=header_paramters)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('ValidateAccountName', response)
return deserialized
示例8: create_organization
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def create_organization(self, region_code, organization_name):
"""Create a new organization for user"""
url = '/_apis/HostAcquisition/collections'
#construct query parameters
query_paramters = {}
query_paramters['collectionName'] = organization_name
query_paramters['preferredRegion'] = region_code
query_paramters['api-version'] = '4.0-preview.1'
#construct header parameters
header_paramters = {}
header_paramters['Accept'] = 'application/json'
header_paramters['Content-Type'] = 'application/json'
if self._user_mgr.is_msa_account():
header_paramters['X-VSS-ForceMsaPassThrough'] = 'true'
#construct the payload
payload = {}
payload['VisualStudio.Services.HostResolution.UseCodexDomainForHostCreation'] = 'true'
request = self._create_organization_client.post(url=url, params=query_paramters, content=payload)
response = self._create_organization_client.send(request, headers=header_paramters)
# Handle Response
deserialized = None
if response.status_code // 100 != 2:
logging.error("GET %s", request.url)
logging.error("response: %s", response.status_code)
logging.error(response.text)
raise HttpOperationError(self._deserialize, response)
else:
deserialized = self._deserialize('NewOrganization', response)
return deserialized
示例9: test_invalid_organization_without_credential
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def test_invalid_organization_without_credential(self):
no_cred_organization_manager = OrganizationManager(creds=None)
with self.assertRaises(HttpOperationError):
no_cred_organization_manager.list_organizations()
示例10: test_invalid_create_duplicated_organization
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def test_invalid_create_duplicated_organization(self):
existing_organization_names = [
org.accountName for org in self.organization_manager.list_organizations().value
]
# If there is no existing organization, we will skip this test
if existing_organization_names.count == 0:
raise unittest.SkipTest("There is no existing organization. Cannot create a duplicate.")
organization_name = existing_organization_names[0]
with self.assertRaises(HttpOperationError):
self.organization_manager.create_organization('CUS', organization_name)
示例11: try_delete_device
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def try_delete_device(self, device_id):
try:
run_with_retry(
self.service.delete_device,
(device_id,),
{"if_match": "*", "custom_headers": self.headers()},
)
return True
except HttpOperationError:
return False
示例12: try_delete_module
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def try_delete_module(self, device_id, module_id):
try:
run_with_retry(
self.service.delete_module,
(device_id, module_id),
{"if_match": "*", "custom_headers": self.headers()},
)
return True
except HttpOperationError:
return False
示例13: get_teams_channels
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def get_teams_channels(
self, team_id, custom_headers=None, raw=False, **operation_config
):
"""Fetches channel list for a given team.
Fetch the channel list.
:param team_id: Team Id
:type team_id: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: ConversationList or ClientRawResponse if raw=true
:rtype: ~botframework.connector.teams.models.ConversationList or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`HttpOperationError<msrest.exceptions.HttpOperationError>`
"""
# Construct URL
url = self.get_teams_channels.metadata["url"]
path_format_arguments = {
"teamId": self._serialize.url("team_id", team_id, "str")
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters["Accept"] = "application/json"
if custom_headers:
header_parameters.update(custom_headers)
# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)
if response.status_code not in [200]:
raise HttpOperationError(self._deserialize, response)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize("ConversationList", response)
if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response
return deserialized
示例14: get_team_details
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def get_team_details(
self, team_id, custom_headers=None, raw=False, **operation_config
):
"""Fetches details related to a team.
Fetch details for a team.
:param team_id: Team Id
:type team_id: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: TeamDetails or ClientRawResponse if raw=true
:rtype: ~botframework.connector.teams.models.TeamDetails or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`HttpOperationError<msrest.exceptions.HttpOperationError>`
"""
# Construct URL
url = self.get_team_details.metadata["url"]
path_format_arguments = {
"teamId": self._serialize.url("team_id", team_id, "str")
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters["Accept"] = "application/json"
if custom_headers:
header_parameters.update(custom_headers)
# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)
if response.status_code not in [200]:
raise HttpOperationError(self._deserialize, response)
deserialized = None
if response.status_code == 200:
deserialized = self._deserialize("TeamDetails", response)
if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response
return deserialized
示例15: delete
# 需要导入模块: from msrest import exceptions [as 别名]
# 或者: from msrest.exceptions import HttpOperationError [as 别名]
def delete(
self, workspace_name, spark_pool_name, batch_id, custom_headers=None, raw=False, **operation_config):
"""Cancels a running spark batch job.
:param workspace_name: The name of the workspace to execute operations
on.
:type workspace_name: str
:param spark_pool_name: Name of the spark pool. "ondemand" targets the
ondemand pool.
:type spark_pool_name: str
:param batch_id: Identifier for the batch job.
:type batch_id: int
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: None or ClientRawResponse if raw=true
:rtype: None or ~msrest.pipeline.ClientRawResponse
:raises:
:class:`HttpOperationError<msrest.exceptions.HttpOperationError>`
"""
# Construct URL
url = self.delete.metadata['url']
path_format_arguments = {
'workspaceName': self._serialize.url("workspace_name", workspace_name, 'str', skip_quote=True),
'SynapseDnsSuffix': self._serialize.url("self.config.synapse_dns_suffix", self.config.synapse_dns_suffix, 'str', skip_quote=True),
'livyApiVersion': self._serialize.url("self.config.livy_api_version", self.config.livy_api_version, 'str', skip_quote=True),
'sparkPoolName': self._serialize.url("spark_pool_name", spark_pool_name, 'str'),
'batchId': self._serialize.url("batch_id", batch_id, 'int')
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
if custom_headers:
header_parameters.update(custom_headers)
# Construct and send request
request = self._client.delete(url, query_parameters)
response = self._client.send(request, header_parameters, stream=False, **operation_config)
if response.status_code not in [200]:
raise HttpOperationError(self._deserialize, response)
if raw:
client_raw_response = ClientRawResponse(None, response)
return client_raw_response