Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for using unicode characters in update_config() #840

Merged
merged 2 commits into from
Aug 19, 2023
Merged

Support for using unicode characters in update_config() #840

merged 2 commits into from
Aug 19, 2023

Conversation

LeoHsiao1
Copy link

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
Copy link
Author

There is another update_config() defined in view.py, I'm not sure what it's for.

def update_config(self, config: str) -> str:
"""
Update the config.xml to the view
"""
url = self.get_config_xml_url()
config = str(config) # cast unicode in case of Python 2
response = self.get_jenkins_obj().requester.post_url(
url, params={}, data=config
)
return response.text

@lechat lechat merged commit 231cea3 into pycontribs:master Aug 19, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants