[dput-ng-maint] Bug#893309: post_upload_command output broken (Python 3 issue?)

Mattia Rizzolo mattia at debian.org
Mon Mar 26 00:49:58 UTC 2018


Control: tag -1 patch

On Sat, Mar 17, 2018 at 02:43:15PM -0700, Russ Allbery wrote:
> dput-ng throws an exception when reporting the output from a
> post_upload_command and does not show the output.  The exception is:
> 
> Traceback (most recent call last):
>   File "/usr/bin/dput", line 124, in <module>
>     upload_package(changes, args)
>   File "/usr/lib/python3/dist-packages/dput/uploader.py", line 352, in invoke_dput
>     logger.warning("No hooks defined in the profile. "
>   File "/usr/lib/python3.6/contextlib.py", line 88, in __exit__
>     next(self.gen)
>   File "/usr/lib/python3/dist-packages/dput/uploader.py", line 175, in uploader
>     obj._post_hook()
>   File "/usr/lib/python3/dist-packages/dput/uploader.py", line 68, in _post_hook
>     self._run_hook("post_upload_command")
>   File "/usr/lib/python3/dist-packages/dput/uploader.py", line 86, in _run_hook
>     sys.stdout.write(output)  # XXX: Fixme
> TypeError: write() argument must be str, not bytes
> 
> Looks like a Python 2 to Python 3 unicode handling issue?

I believe so, yes.

Russ, could you please double check this (currently untested) patch
solves the issue for you?

diff --git a/dput/uploader.py b/dput/uploader.py
index 19cb7f1..3c5df71 100644
--- a/dput/uploader.py
+++ b/dput/uploader.py
@@ -84,6 +84,7 @@ class AbstractUploader(object):
                     return

             sys.stdout.write(output)  # XXX: Fixme
+            sys.stdout.flush()
             if ret != 0:
                 raise DputError(
                     "Command `%s' returned an error: %s [err=%d]" % (
diff --git a/dput/util.py b/dput/util.py
index 6275a5b..6d42edf 100644
--- a/dput/util.py
+++ b/dput/util.py
@@ -96,6 +96,8 @@ def run_command(command):
         logger.error("Could not execute %s: %s" % (" ".join(command), e))
         return (None, None, -1)
     (output, stderr) = pipe.communicate()
+    output = output.decode('utf-8', errors='replace')
+    stderr = stderr.decode('utf-8', errors='replace')
     #if pipe.returncode != 0:
     #   error("Command %s returned failure: %s" % (" ".join(command), stderr))
     return (output, stderr, pipe.returncode)


-- 
regards,
                        Mattia Rizzolo

GPG Key: 66AE 2B4A FCCF 3F52 DA18  4D18 4B04 3FCD B944 4540      .''`.
more about me:  https://mapreri.org                             : :'  :
Launchpad user: https://launchpad.net/~mapreri                  `. `'`
Debian QA page: https://qa.debian.org/developer.php?login=mattia  `-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/dput-ng-maint/attachments/20180326/603f82c3/attachment.sig>


More information about the dput-ng-maint mailing list