# import httplib # http_client = None # http_client = httplib.HTTPConnection('localhost', 8080, timeout=30) # http_client.request('GET', '/jenkins/api/json?pretty=true') # response = http_client.getresponse() # print response.status # print response.read() # http_client.request('POST', '/jenkins/job/check_python_version/polling') # response = http_client.getresponse() # print response.status # print response.read() # print response.getheaders() import urllib2 import urllib # print urllib2.urlopen('http://localhost:8080/jenkins/api/json?pretty=true').read() post_data = urllib.urlencode({}) response = urllib2.urlopen('http://localhost:8080/jenkins/job/check_python_version/polling', post_data) print response.read() print response.getheaders()
#coding:utf-8 # http://docs.python-requests.org/en/latest/user/quickstart/#make-a-request import requests from requests.auth import HTTPBasicAuth # GET print requests.get('http://localhost:8080/jenkins/api/json?pretty=true').text # POST with basic auth url = 'http://localhost:8080/jenkins/job/check_python_version/disable' r = requests.post(url, data={}, auth=('admin', 'admin')) print r.status_code print r.headers print r.reason