如何使用python访问GerritRESTAPI
首先,我对gerrit的理解有限 我正在尝试使用python访问GerritRESTAPI,但无法做到这一点。我想获取与帐户(提交、审核)相关的所有信息 我得到的错误是:如何使用python访问GerritRESTAPI,python,gerrit,Python,Gerrit,首先,我对gerrit的理解有限 我正在尝试使用python访问GerritRESTAPI,但无法做到这一点。我想获取与帐户(提交、审核)相关的所有信息 我得到的错误是: ConnectionError: HTTPSConnectionPool(host='xxx.xx.xxx.xxx.com', port=443): Max retries exceeded with url: /login/a/changes/?q=is:open&q=is:close&q=all&o
ConnectionError: HTTPSConnectionPool(host='xxx.xx.xxx.xxx.com', port=443): Max retries exceeded with url: /login/a/changes/?q=is:open&q=is:close&q=all&o=DETAILED_ACCOUNTS&o=ALL_REVISIONS&o=ALL_COMMITS&o=ALL_FILES&o=MESSAGES (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x825bad0>: Failed to establish a new connection: [Errno 110] Connection timed out',))
ConnectionError:HTTPSConnectionPool(host='xxx.xx.xxx.xxx.com',port=443):url超过最大重试次数:/login/a/changes/?q=is:open&q=is:close&q=all&o=DETAILED\u ACCOUNTS&o=all\u REVISIONS&o=all\u提交&o=all\u文件&o=MESSAGES(由NewConnectionError(':未能建立新连接:[Errno 110]连接超时,))
如果我将查询复制粘贴到url中,就可以获取信息,但不能通过python。怎么做?
如果问题不清楚,请评论/编辑。
谢谢您遇到来自请求库(pygerrit2 is)的连接错误-这是因为您的连接超时。为了避免这种情况,我建议使用类似的库。退避将捕获此连接错误并重试建立连接。这是很容易做到的装饰和进口
from requests.auth import HTTPDigestAuth
from pygerrit2 import GerritRestAPI, HTTPBasicAuth
import backoff
import requests
@backoff.on_exception(backoff.expo,
requests.exceptions.ConnectionError,
max_time=10)
def makeGerritAPICall():
auth = HTTPBasicAuth('user', 'password')
rest = GerritRestAPI(url='https://xxx.xx.xxx.xxx.com/', auth = auth)
changes = rest.get("changes/?q=is:open&q=is:close&q=all&o=DETAILED_ACCOUNTS&o=ALL_REVISIONS&o=ALL_COMMITS&o=ALL_FILES&o=MESSAGES", headers={'Content-Type': 'application/json'})
以下函数将重试发出任何遇到ConnectionError的请求10秒钟,然后失败并引发ConnectionError
我建议访问backoff git自述文档,因为它们包含大量关于backoff的有用信息。我在这里是一个完全的初学者。如何打印变量更改中得到的值?
from requests.auth import HTTPDigestAuth
from pygerrit2 import GerritRestAPI, HTTPBasicAuth
import backoff
import requests
@backoff.on_exception(backoff.expo,
requests.exceptions.ConnectionError,
max_time=10)
def makeGerritAPICall():
auth = HTTPBasicAuth('user', 'password')
rest = GerritRestAPI(url='https://xxx.xx.xxx.xxx.com/', auth = auth)
changes = rest.get("changes/?q=is:open&q=is:close&q=all&o=DETAILED_ACCOUNTS&o=ALL_REVISIONS&o=ALL_COMMITS&o=ALL_FILES&o=MESSAGES", headers={'Content-Type': 'application/json'})