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


Python exceptions.HttpOperationError方法代碼示例

本文整理匯總了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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:19,代碼來源:project_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:26,代碼來源:project_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:27,代碼來源:organization_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-iot-sdk-python,代碼行數:24,代碼來源:service_helper.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:30,代碼來源:pool_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:32,代碼來源:user_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:36,代碼來源:organization_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:37,代碼來源:organization_manager.py

示例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() 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:6,代碼來源:test_organization_manager.py

示例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) 
開發者ID:Azure,項目名稱:azure-functions-devops-build,代碼行數:14,代碼來源:test_organization_manager.py

示例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 
開發者ID:Azure,項目名稱:azure-iot-sdk-python,代碼行數:12,代碼來源:service_helper.py

示例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 
開發者ID:Azure,項目名稱:azure-iot-sdk-python,代碼行數:12,代碼來源:service_helper.py

示例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 
開發者ID:microsoft,項目名稱:botbuilder-python,代碼行數:55,代碼來源:teams_operations.py

示例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 
開發者ID:microsoft,項目名稱:botbuilder-python,代碼行數:55,代碼來源:teams_operations.py

示例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 
開發者ID:Azure,項目名稱:azure-cli-extensions,代碼行數:54,代碼來源:spark_batch_operations.py


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