我有一个正在尝试测试的文件。我已经能够测试所有的东西,除了引起一个库的ClientRequestError。我想模拟到https://dev.azure.com/ms/_apis/projects/calculator的连接,并在本质上导致到此端点的连接错误,因此库抛出ClientRequestError。
这就是我想要测试的
from azure.devops.connection import Connection
from azure.devops.exceptions import AzureDevOpsServiceError
from msrest.exceptions import ClientRequestError
...
connection = Connection(
base_url=f"https://dev.azure.com/ms"
)
try:
core_client = connection.clients.get_core_client()
core_client.get_project("calculator")
except AzureDevOpsServiceError as exception:
_LOGGER.warning(exception)
...
except ClientRequestError as exception:
_LOGGER.warning(exception)
...我想要介绍的是ClientRequestError。
发布于 2020-04-13 10:56:42
我看到你没有提供连接构造函数的凭据。您需要通过身份验证才能连接到azure devops服务器。
您可以尝试获取Person Access Token并提供连接到azure devops组织的凭据。看看下面的例子:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.exceptions import AzureDevOpsServiceError
from msrest.exceptions import ClientRequestError
token = 'Personal Access Token'
credentials = BasicAuthentication("", token)
connection = Connection(
base_url=f"https://dev.azure.com/ms",
creds=credentials
)
try:
core_client = connection.clients.get_core_client()
core_client.get_project("calculator")
except AzureDevOpsServiceError as exception:
....您还可以查看示例here。
https://stackoverflow.com/questions/61157430
复制相似问题