问题
My code is given below
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
When I execute this, it just prints "Hello" and then hangs. What could be the reason for this ?
N.B. I am running this in my corporate network behind a proxy.
Reference: http://pythonhosted.org/jenkinsapi/using_jenkinsapi.html#example-1-get-version-of-jenkins
When I killed the command, I get the following error.
File "C:\Python27\lib\ssl.py", line 643, in read
v = self._sslobj.read(len)
Complete log.
>>> 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:
The error on v = self._sslobj.read(len)
implies you interrupted while read was in progress. It seems to be completely undocumented, but jenkinsapi tries to download information on every job when it starts and if your Jenkins repo is huge it's gonna take forever. It's possible to set lazy=True but it will still try to load all the jobs when you try to access a single job. Probably better to use some other library.
server = Jenkins(jenkins_url, username = 'foouser', password = 'foopassword', lazy=True)
来源:https://stackoverflow.com/questions/41010989/call-to-jenkinsapihttps-just-hangs