[python]python-jenkins报错TypeError: ‘bytes‘ object does not support item assignment
File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 379, in maybe_add_crumbreq.headers[self.crumb['crumbRequestField']] = self.crumb['crumb']TypeError: 'bytes' object does not supp
·
Traceback (most recent call last):
File "delete_jenkins_job.py", line 42, in <module>
main()
File "delete_jenkins_job.py", line 37, in main
delete_jenkins_workspace(server, job)
File "delete_jenkins_job.py", line 14, in delete_jenkins_workspace
server.wipeout_job_workspace(job)
File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 1426, in wipeout_job_workspace
locals()), b''))
File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 557, in jenkins_open
return self.jenkins_request(req, add_crumb, resolve_auth).text
File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 573, in jenkins_request
self.maybe_add_crumb(req)
File "/usr/local/lib/python3.5/dist-packages/jenkins/__init__.py", line 379, in maybe_add_crumb
req.headers[self.crumb['crumbRequestField']] = self.crumb['crumb']
TypeError: 'bytes' object does not support item assignment
执行Jenkins.wipeout_job_workspace()
时可能报此错误
3. 环境
python版本:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
- 原因和解决方案
在该模块的源文件site-packages\jenkins\__init__.py
中,大约1426行,调用requests.Request
时传入了一个参数,b''
,导致异常,此参数为发起http请求时的自定义请求头,应该传入字典类型或None
self.jenkins_open(requests.Request('POST',
self._build_url(WIPEOUT_JOB_WORKSPACE,
locals()), b''))
去掉b''
即可正常使用
self.jenkins_open(requests.Request('POST',
self._build_url(WIPEOUT_JOB_WORKSPACE,
locals())))
工具简介
python-jenkins是一个通过Jenkins REST API来操作Jenkins的python模块,安装方法
pip install python-jenkins
更多推荐
已为社区贡献1条内容
所有评论(0)