pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
859 stars 485 forks source link

Support for using unicode characters in update_config() #840

Closed LeoHsiao1 closed 1 year ago

LeoHsiao1 commented 1 year ago

Hi! Currently, update_config() converts the config to str type without encoding format. So it does not support unicode characters. For example:

>>> jk.get_job('job1').update_config('中文') 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Leo\AppData\Local\Programs\Python\Python39\lib\site-packages\jenkinsapi\job.py", line 640, in update_config
    response = self.jenkins.requester.post_url(url, params={}, data=config)
  ...
  File "C:\Users\Leo\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 164, in _encode
    raise UnicodeEncodeError(
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: Body ('中文') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

So I submitted this PR to encode the config in utf-8 by default. Looking forward to your review.

LeoHsiao1 commented 1 year ago

There is another update_config() defined in view.py, I'm not sure what it's for. https://github.com/pycontribs/jenkinsapi/blob/ec2a23ff4d2ff539de34810da0a4189c6be1eb41/jenkinsapi/view.py#L184-L194