【发布时间】:2018-05-26 08:33:14
【问题描述】:
我正在使用以下命令行调用在 jenkins CLI 服务器上执行一个 groovy 脚本:
curl --user 'Knitschi:myPassword' -H "Jenkins-Crumb:1234" --data-urlencode "script=println 'Hello nice jenkins-curl-groovy world!'" localhost:8080/scriptText
我目前正在将我的 bash 脚本转换为 python,我想使用 python requests 包 (http://docs.python-requests.org/en/master/) 执行与上述调用相同的操作。
目前为止
import requests
url = 'http://localhost:8080/scriptText'
myAuth = ('Knitschi', 'myPassword')
crumbHeader = { 'Jenkins-Crumb' : '1234'}
scriptData = "script=println 'Hello cruel jenkins-python-groovy world!'"
response = requests.post(url, auth=myAuth, headers=crumbHeader, data=scriptData)
print(response.text)
response.raise_for_status()
当命令行打印预期的字符串时,python 代码不会。 它也不会引发异常。
我也不确定应该使用requests.get() 还是requests.post()。我的网络技术知识非常有限。
感谢您的宝贵时间。
【问题讨论】: