Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 9BC52E00C39; Tue, 7 Jun 2016 08:38:02 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high * trust * [192.55.52.115 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id D34FBE00C3E for ; Tue, 7 Jun 2016 08:37:54 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 07 Jun 2016 08:37:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,433,1459839600"; d="scan'208";a="117614712" Received: from tblazejc-mobl.ger.corp.intel.com (HELO lp.ger.corp.intel.com) ([10.252.19.29]) by fmsmga004.fm.intel.com with ESMTP; 07 Jun 2016 08:37:47 -0700 From: Elliot Smith To: toaster@yoctoproject.org Date: Tue, 7 Jun 2016 16:37:29 +0100 Message-Id: <1465313849-20109-8-git-send-email-elliot.smith@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1465313849-20109-1-git-send-email-elliot.smith@intel.com> References: <1465313849-20109-1-git-send-email-elliot.smith@intel.com> Subject: [PATCH][v2 8/8] toaster: open image files in binary mode when sending in response X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 15:38:02 -0000 The view code for downloading image files used the "r" flag to read the file, then used the open file object to form the HTTP response. While this worked in Python 2, Python 3 appears to be more strict about this sort of thing, and Django throws a UnicodeDecodeError when a file opened this way is used in a response. Open the file with the "b" flag (binary mode) so that Django can correctly convert the binary file handle to an HTTP response. Signed-off-by: Elliot Smith Signed-off-by: Ed Bartosh --- bitbake/lib/toaster/toastergui/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 1f908ea..16f98ee 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2339,7 +2339,7 @@ if True: ) if file_name and response_file_name: - fsock = open(file_name, "r") + fsock = open(file_name, "rb") content_type = MimeTypeFinder.get_mimetype(file_name) response = HttpResponse(fsock, content_type = content_type) -- 1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.