From f67e54a35c29d50ab785662aafec85716f64e913 Mon Sep 17 00:00:00 2001 From: Owen W. Taylor Date: Feb 24 2020 20:02:03 +0000 Subject: koji.ClientSession: fix erroneous conversion to latin-1 For Python 3, we need to always encode what we are sending to the server as utf-8; encoding strings that have only latin-1 as latin-1 causes us to send something that the server can't parse. (When no encoding is specified xmlclient.client.dumps creates an XML document with an xml declaration for UTF-8.) --- diff --git a/koji/__init__.py b/koji/__init__.py index 923d8a6..5004d8d 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2580,13 +2580,10 @@ class ClientSession(object): handler = self.baseurl request = dumps(args, name, allow_none=1) if six.PY3: - try: - request.encode('latin-1') - except UnicodeEncodeError: - # if string is not converted to UTF, requests will raise an error - # on identical check before sending data - # py3 string throws UnicodeEncodeError - request = request.encode('utf-8') + # For python2, dumps() without encoding specified means return a str + # encoded as UTF-8. For python3 it means "return a str with an appropriate + # xml declaration for encoding as UTF-8". + request = request.encode('utf-8') headers = [ # connection class handles Host ('User-Agent', 'koji/1'),