self, url: str, method: str, data: Optional[Any] = None, timeout: int = 30
) -> requests.Response | Tuple[requests.Response, Optional[Dict[str, Any] | str]]:
"""Execute the request."""
+ # Encode string data as UTF-8 to handle Unicode characters
+ if isinstance(data, str):
+ data = data.encode("utf-8")
+
resp: requests.Response = self.r.request(method, self.endpoint + url, data=data, timeout=timeout)
# Some massaging to make our gerrit python code work
POST /changes/{change-id}/revisions/{revision-id}/review
"""
- log.info(fqdn, gerrit_project, changeid)
+ log.info(f"Voting on change: fqdn={fqdn}, project={gerrit_project}, changeid={changeid}")
access_str = "changes/{}/revisions/2/review".format(changeid)
headers = {"Content-Type": "application/json; charset=UTF-8"}
self.r.headers.update(headers)
def votes(ctx, organization, repo, pr):
"""Helper for votes."""
approval_list = prvotes(organization, repo, pr)
- log.info("Approvals:", approval_list)
+ log.info(f"Approvals: {approval_list}")
@click.command(name="list")
has_issues = has_issues or False
has_wiki = has_wiki or False
has_projects = has_projects or False
- log.info("Creating repo under organization: ", orgName)
+ log.info(f"Creating repo under organization: {orgName}")
try:
org = g.get_organization(orgName)
except GithubException as ghe:
}
}
- json_data = json.dumps(target).encode(encoding="latin-1")
+ json_data = json.dumps(target).encode(encoding="utf-8")
r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data)
}
}
- json_data = json.dumps(privileges).encode(encoding="latin-1")
+ json_data = json.dumps(privileges).encode(encoding="utf-8")
r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data)
privileges = r.json()
}
}
- json_data = json.dumps(role).encode(encoding="latin-1")
+ json_data = json.dumps(role).encode(encoding="utf-8")
log.debug("Sending role {} to Nexus".format(json_data))
r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data)
for role in extra_roles:
user["data"]["roles"].append(self.get_role(role))
- json_data = json.dumps(user).encode(encoding="latin-1")
+ json_data = json.dumps(user).encode(encoding="utf-8")
user = requests.post(url, auth=self.auth, headers=self.headers, data=json_data)
repo = {"data": data}
- json_data = json.dumps(repo).encode(encoding="latin-1")
+ json_data = json.dumps(repo).encode(encoding="utf-8")
requests.put(url, auth=self.auth, headers=self.headers, data=json_data)
--- /dev/null
+---
+fixes:
+ - |
+ Fix UnicodeEncodeError in Gerrit API requests when responses contain
+ Unicode characters. JSON string data is now properly encoded as UTF-8
+ in the RestApi._request() method, preventing 'latin-1' codec errors
+ when user names or group names contain special characters (e.g., 'š').
+
+ This fixes failures in commands like:
+ lftools gerrit addgithubrights <fqdn> <project>
+
+ - |
+ Fix logging TypeError in GitHub create-repo command. Changed from
+ using comma-separated arguments (which caused format string errors)
+ to using f-string formatting for proper message construction.