【Python】【应用】Python应用之玩转gerrit系列之一——搭建基础环境
1、缘起
2、准备工作
2.1 安装python3
windows 7(64bits) python 3.8.6
Pygerrit2 is compatible with Python 2.6 and Python 2.7. Support for
Python 3 is experimental.
2.2 安装相关库
2.3 获取http的用户名和密码
也可直接进入页面:https://gerrit.zte.com.cn/#/settings/http-password查看。

3、牛刀小试
from requests.auth import HTTPDigestAuth
from pygerrit2.rest import GerritRestAPI
if __name__ == '__main__':
auth = HTTPDigestAuth('qxhgd@xxx.com', 'pwd2qxhgd') #获取auth信息
rest = GerritRestAPI(url='https://gerrit.xxx.com', auth=auth) #用auth信息去访问gerrit的rest接口
changes = rest.get("/changes/?q=owner:self%20status:open") #用rest接口去查询相关信息,json格式返回
print(changes) #将json串打印出来
https://gerrit.xxx.com/#/q/owner:qxhgd%2540xxx.com+status:open
或在gerrit页面上输入下面过滤条件的结果。

4、命令汇总
python -m pip install --upgrade pip #升级pip
pip3 install requests #直接使用官方源安装
pip3 install -i https://pypi.douban.com/simple requests #使用镜像安装requests
pip3 install pygerrit2-i https://pypi.douban.com/simple #使用镜像安装pygerrit2, 用镜像安装可用上述两种格式
5、参考资料
如本文对你有些许帮助,欢迎打赏或通过里面链接购买书籍:
支付宝打赏方式及我的购物小店
来源:花神庙码农