拨打JenkinsAPI(https)只是挂起

时间:2016-12-07 06:41:21

标签: python ssl https ssl-certificate jenkins-api

我的代码如下:

from jenkinsapi.jenkins import Jenkins

def get_server_instance():
    jenkins_url = 'https://<privateJenkinsServer>:<port>'
    print "Hello" 
   server = Jenkins(jenkins_url, username = 'foouser', password = 'foopassword')
    return server

if __name__ == '__main__':
    print get_server_instance().version

当我执行此操作时,它只打印“Hello”然后挂起。这可能是什么原因?

N.B。我在代理服务器后面的公司网络中运行它。

参考:http://pythonhosted.org/jenkinsapi/using_jenkinsapi.html#example-1-get-version-of-jenkins

当我杀死命令时,我收到以下错误。

File "C:\Python27\lib\ssl.py", line 643, in read
    v = self._sslobj.read(len)

完成日志。

>>> execfile('C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py')
started
https://jenkm1.discoverfinancial.com:8443

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    execfile('C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py')
  File "C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py", line 28, in <module>
    print get_server_instance().version
  File "C:\Users\idatta\Project\Python\Demo\JenkinsAPI_v1.py", line 19, in get_server_instance
    server = Jenkins(jenkins_url, username = 'idatta', password = 'Gr33nCard_1', ssl_verify=False)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkins.py", line 59, in __init__
    JenkinsBase.__init__(self, baseurl, poll=not lazy)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 35, in __init__
    self.poll()
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 61, in poll
    data['jobs'] = self.resolve_job_folders(data['jobs'])
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 100, in resolve_job_folders
    jobs += self.process_job_folder(job, self.baseurl)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 112, in process_job_folder
    result += self.process_job_folder(job, folder_path)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 112, in process_job_folder
    result += self.process_job_folder(job, folder_path)
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 107, in process_job_folder
    tree='jobs[name,color]')
  File "C:\Python27\lib\site-packages\jenkinsapi\jenkinsbase.py", line 79, in get_data
    response = requester.get_url(url, params)
  File "C:\Python27\lib\site-packages\jenkinsapi\utils\requester.py", line 109, in get_url
    return requests.get(self._update_url_scheme(url), **requestKwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 70, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 423, in send
    timeout=timeout
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 594, in urlopen
    chunked=chunked)
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 384, in _make_request
    httplib_response = conn.getresponse(buffering=True)
  File "C:\Python27\lib\httplib.py", line 1136, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\Python27\lib\socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "C:\Python27\lib\ssl.py", line 756, in recv
    return self.read(buflen)
  File "C:\Python27\lib\ssl.py", line 643, in read
    v = self._sslobj.read(len)
KeyboardInterrupt
>>> 

1 个答案:

答案 0 :(得分:0)

v = self._sslobj.read(len)上的错误意味着您在读取过程中被中断。它似乎完全没有记录,但jenkinsapi试图在每个工作开始时下载每个工作的信息,如果你的Jenkins回购很大,它将永远消失。可以设置lazy = True但是当您尝试访问单个作业时,它仍会尝试加载所有作业。可能更好地使用其他一些库。

server = Jenkins(jenkins_url, username = 'foouser', password = 'foopassword', lazy=True)