changeset: 86211:8781436a840e tag: tip user: W. Trevor King date: Fri Oct 11 09:27:35 2013 -0700 files: Lib/distutils/command/upload.py description: distutils.command.upload: Convert response from bytes to str Avoid: Traceback (most recent call last): File "setup.py", line 61, in 'html2text (>=3.0.1)', File "/.../python3.2/distutils/core.py", line 148, in setup dist.run_commands() File "/.../python3.2/distutils/dist.py", line 917, in run_commands self.run_command(cmd) File "/.../python3.2/distutils/dist.py", line 936, in run_command cmd_obj.run() File "/.../python3.2/distutils/command/upload.py", line 66, in run self.upload_file(command, pyversion, filename) File "/.../python3.2/distutils/command/upload.py", line 201, in upload_file msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) TypeError: sequence item 1: expected str instance, bytes found by converting the bytes returned by HTTPResponse.read [1] to a string before joinging it with other strings. HTTPResponse.headers supports the Message interface [2], so we can use get_param to extract the charset [3], falling back on ISO-8859-1 [4]. [1]: http://docs.python.org/3/library/http.client.html#http.client.HTTPResponse.read [2]: http://docs.python.org/3/library/http.client.html#httpmessage-objects [3]: http://docs.python.org/3/library/email.message.html#email.message.Message.get_param [4]: http://tools.ietf.org/html/rfc2616#section-3.7.1 diff -r a4515186bf9c -r 8781436a840e Lib/distutils/command/upload.py --- a/Lib/distutils/command/upload.py Fri Oct 11 12:09:51 2013 -0400 +++ b/Lib/distutils/command/upload.py Fri Oct 11 09:27:35 2013 -0700 @@ -198,5 +198,6 @@ self.announce('Upload failed (%s): %s' % (r.status, r.reason), log.ERROR) if self.show_response: - msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) + charset = r.headers.get_param('charset', 'ISO-8859-1') + msg = '\n'.join(('-' * 75, str(r.read(), charset), '-' * 75)) self.announce(msg, log.INFO)