简体   繁体   English

Python-Jenkins API连接错误

[英]Python-Jenkins API Connection Error

I'm trying to use python-jenkins to connect to a jenkins instance. 我正在尝试使用python-jenkins连接到jenkins实例。

My code snippet is as follows: 我的代码段如下:

import jenkins

JENKINS_URL = 'xxxx'
JENKINS_USER = 'yyyy'
JENKINS_PASSWORD = 'zzzz'

server = jenkins.Jenkins(JENKINS_URL, username=JENKINS_USER, password=JENKINS_PASSWORD)

jobs = server.get_jobs()

for job in jobs:
    print "Job: {0}".format(job.name)

The username and password are valid; 用户名和密码有效; I can log in to jenkins via the web using them without issue. 我可以使用它们通过网络通过jenkins登录。 However, here, I get an error. 但是,在这里,我得到一个错误。 The traceback I get is as follows: 我得到的追溯如下:

Traceback (most recent call last):
    File "apitest.py", line 11, in <module>
        jobs = server.get_jobs()
    File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 540, in get_jobs
        return self.get_info()['jobs']
    File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 422, in get_info
        Request(self.server + INFO)))
    File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 312, in jenkins_open
        self.maybe_add_crumb(req)
    File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 230, in maybe_add_crumb
        self.server + CRUMB_URL), add_crumb=False)
    File "/usr/lib/python2.7/site-packages/jenkins/__init__.py", line 330, in jenkins_open
        e.code, e.msg)
jenkins.JenkinsException: Error in request. Possibly authentication failed [500]: Server Error

Can anyone shed any light on the problem? 任何人都可以阐明这个问题吗? I'm using python-jenkins version 0.4.8, and our jenkins box is version 1.541. 我正在使用python-jenkins版本0.4.8,而我们的jenkins框是版本1.541。 The only other useful data point I can think of is that the jenkins box is configured to support https access only. 我能想到的唯一其他有用的数据点是,詹金斯框已配置为仅支持https访问。

NB I've also tried jenkinsapi, but get a similar error 注意:我也尝试过jenkinsapi,但收到类似错误

The problem here was that I was using the password for the account, whereas actually you need to use the API token. 这里的问题是我正在使用该帐户的密码,而实际上您需要使用API​​令牌。

The documentation (and variable names) in jenkinsapi don't make this clear at all! jenkinsapi中的文档(和变量名)一点都不明确!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM