【发布时间】:2021-01-21 15:18:18
【问题描述】:
我正在使用 pygerrit2 对我的 gerrit 服务器进行身份验证并遇到以下错误,用户名和密码正确,因为我使用相同的用户名和密码从 gerrit UI 手动登录,为什么会出现此错误以及如何解决?
from pygerrit2 import GerritRestAPI, HTTPBasicAuth
auth = HTTPBasicAuth('username', 'password')
print auth
rest = GerritRestAPI(url='https://tech.company.com', auth=auth)
changes = rest.get("/changes/?q=owner:self%20status:open")
错误:-
Traceback (most recent call last):
File "get_related_changes.py", line 62, in <module>
changes = rest.get("/changes/?q=owner:self%20status:open")
File "/Library/Python/2.7/site-packages/pygerrit2/rest/__init__.py", line 156, in get
decoded_response = _decode_response(response)
File "/Library/Python/2.7/site-packages/pygerrit2/rest/__init__.py", line 51, in _decode_response
response.raise_for_status()
File "/Library/Python/2.7/site-packages/requests/models.py", line 939, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://tech.company.com/a/changes/?q=owner:self%20status:open
【问题讨论】:
-
您的 gerrit 是否配置为使用基本身份验证?
-
我相信旧版本的 gerrit 仅默认使用 HTTP Digest,而当前版本默认使用 HTTP Basic,但有多种不同的选项可以选择使用哪个密码,默认情况下它与您使用的密码不同在 GUI 中使用,它是用于 git+https 的随机生成的(您可以从用户设置页面的 GUI 中看到)。
-
@abarnert - 如何知道我的 gerrit 是否配置为使用基本身份验证?
-
@user3508811 如果 gerrit 版本早于 2.14,那么它很可能使用摘要身份验证。以后的版本使用基本的。