from jenkinsapi.jenkins import Jenkins
JENKINS_URL = "<jenkins-url>"
JENKINS_USERNAME = "<username>"
JENKINS_PASSWORD = "<password>"
self.jenkins_server = Jenkins(JENKINS_URL, username=JENKINS_USERNAME, password=JENKINS_PASSWORD)
它给了我以下错误:HTTPError: 401 Client Error: Unauthorized for url
StackTrace:
Failed request at http://<jenkins-url>/api/python with params: {'tree': 'jobs[name,color,url]'} jobs[name,color,url]
Traceback (most recent call last):
File "minimal_test_jenkins.py", line 11, in __init__
self.jenkins_server = Jenkins(JENKINS_URL, username=JENKINS_USERNAME, password=JENKINS_PASSWORD)
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/jenkinsapi/jenkins.py", line 77, in __init__
JenkinsBase.__init__(self, baseurl, poll=not lazy)
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 38, in __init__
self.poll()
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 60, in poll
data = self._poll(tree=tree)
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/jenkinsapi/jenkins.py", line 82, in _poll
if not tree else tree)
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 84, in get_data
response.raise_for_status()
File "/Users/bapac/Downloads/jenkins/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://<jenkins-url>/api/python?tree=jobs%5Bname%2Ccolor%2Curl%5D
答案 0 :(得分:1)
python3 -m pip freeze | grep requests
python3 -m pip install requests==2.25.0
或python2
会解决问题
答案 1 :(得分:0)
未经授权的网址,即401客户端错误表示三件事之一是错误的 没有提供所需的Jenkins用户名/密码或其他凭证。
我通过更正密码(以前是不正确的!)来解决它的问题