diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 55bd138a..e427a893 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -931,7 +931,8 @@ def st_upload(parser, args, output_manager): if error.http_response_content: if msg: msg += ': ' - msg += error.http_response_content[:60] + msg += (error.http_response_content + .decode('utf8')[:60]) msg = ': %s' % msg else: msg = ': %s' % error diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py index 13c26634..01288c1f 100644 --- a/tests/unit/test_shell.py +++ b/tests/unit/test_shell.py @@ -531,6 +531,27 @@ class TestShell(testtools.TestCase): 'x-object-meta-mtime': mock.ANY}, response_dict={}) + @mock.patch('swiftclient.service.SwiftService.upload') + def test_upload_object_with_account_readonly(self, upload): + argv = ["", "upload", "container", self.tmpfile] + upload.return_value = [ + {"success": False, + "headers": {}, + "action": 'create_container', + "error": swiftclient.ClientException( + 'Container PUT failed', + http_status=403, + http_reason='Forbidden', + http_response_content=b'<html><h1>Forbidden</h1>') + }] + + with CaptureOutput() as output: + swiftclient.shell.main(argv) + self.assertTrue(output.err != '') + warning_msg = "Warning: failed to create container 'container': " \ + "403 Forbidden" + self.assertTrue(output.err.startswith(warning_msg)) + @mock.patch('swiftclient.service.Connection') def test_upload_delete_slo_segments(self, connection): # Upload delete existing segments