, , , , Python 3 httplib2, . Jenkins, API Jenkins. Jenkins, Token API.
b64encode expects a binary string of ASCII characters. With Python 3, an Error type will be raised if a simple string is passed into it. To get around this, the "user: api_token" part of the header must be encoded using the "ascii" or "utf-8" passed to b64encode, then the resulting byte string must be decoded to a simple string before being placed in the header. The following code did what I needed:
import httplib2, base64
cred = base64.b64encode("{0}:{1}".format(
<user>, <api_token>).encode('utf-8')).decode()
headers = {'Authorization': "Basic %s" % cred}
h = httplib2.Http('.cache')
response, content = h.request("http://my.jenkins.server/job/my_job/enable",
"GET", headers=headers)
Drewm source
share