首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python -测试azure-devops / msrest ClientRequestError

Python -测试azure-devops / msrest ClientRequestError
EN

Stack Overflow用户
提问于 2020-04-11 21:20:36
回答 1查看 217关注 0票数 1

我有一个正在尝试测试的文件。我已经能够测试所有的东西,除了引起一个库的ClientRequestError。我想模拟到https://dev.azure.com/ms/_apis/projects/calculator的连接,并在本质上导致到此端点的连接错误,因此库抛出ClientRequestError

这就是我想要测试的

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2020-04-13 10:56:42

我看到你没有提供连接构造函数的凭据。您需要通过身份验证才能连接到azure devops服务器。

您可以尝试获取Person Access Token并提供连接到azure devops组织的凭据。看看下面的例子:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61157430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档