From 4c0c3fbb064f576f096699da9aec39a4e776b95c Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Wed, 8 Jun 2022 17:04:02 +0000 Subject: [PATCH] [gerrit] Fix encoding in ChangeEdit gerrit_util.ChangeEdit was passing the result of b64encode into a %s format, which was printing the contents with a bytes prefix (b'...'). Decode the bytes object back to a str object before passing it to '%s' Bug: v8:12849 Change-Id: I8b54b427bbbe8b914444d7486b5a8afbd743de70 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3683382 Reviewed-by: Aravind Vasudevan Commit-Queue: Aravind Vasudevan Auto-Submit: Leszek Swirski Reviewed-by: Gavin Mak --- gerrit_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gerrit_util.py b/gerrit_util.py index 429e1deba..d4ce8953c 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -775,7 +775,8 @@ def ChangeEdit(host, change, path, data): path = 'changes/%s/edit/%s' % (change, urllib.parse.quote(path, '')) body = { 'binary_content': - 'data:text/plain;base64,%s' % base64.b64encode(data.encode('utf-8')) + 'data:text/plain;base64,%s' % + base64.b64encode(data.encode('utf-8')).decode('utf-8') } conn = CreateHttpConn(host, path, reqtype='PUT', body=body) return ReadHttpJsonResponse(conn, accept_statuses=(204, 409))