#1220 Fix non-ascii strings in xmlrpc
Merged 5 years ago by mikem. Opened 5 years ago by tkopecek.
tkopecek/koji issue1219  into  master

file modified
+11
@@ -2389,6 +2389,17 @@ 

          else:

              handler = self.baseurl

          request = dumps(args, name, allow_none=1)

+         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')

+         except UnicodeDecodeError:

+             # py2 string throws UnicodeDecodeError, but it is already meant

+             # to sent as-is

+             pass

          headers = [

              # connection class handles Host

              ('User-Agent', 'koji/1'),

requests library refuse to upload non-latin-1 strings, convert data to
utf-8 before passing to library.

Fixes: https://pagure.io/koji/issue/1219

I'm not overly happy with this solution. Nevrtheless, encoding it inside dumps or in the ExtendedMarshaller triggers further problems with passing binary strings in py3 and storing them in hub. I'm open to other proposals.

rebased onto 70277ff302f561ebf8e3febf300f3f3ad0d13594

5 years ago

is this a separate change?

rebased onto 250088e

5 years ago

I've put typo fix separately: PR #1243

Definitely not the ideal fix, but it seems to work.

Putting the structural concerns aside, what sticks out to me is that we don't really need to do any of this encoding on py2. Or am I missing something about the issue?

https://github.com/mikem23/koji-playground/commits/pagure/pr/1220

Commit 5ca71d7 fixes this pull-request

Pull-Request has been merged by mikem

5 years ago