This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: distutils/command/upload.py show response gives: TypeError: sequence item 1: expected str instance, bytes found
Type: Stage: resolved
Components: Distutils Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: global name 'r' is not defined in upload.py
View: 12853
Assigned To: eric.araujo Nosy List: eric.araujo, labrat, ned.deily, tarek
Priority: normal Keywords: patch

Created on 2013-10-11 16:31 by labrat, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
show-response-string.patch labrat, 2013-10-11 16:31 Patch decoding the bytes to a string review
Messages (3)
msg199489 - (view) Author: W. Trevor King (labrat) * Date: 2013-10-11 16:31
Avoid:

    Traceback (most recent call last):
      File "setup.py", line 61, in <module>
        '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
msg199492 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-10-11 17:21
This problem has been reported previously as Issue17354, a duplicate of Issue12853 which is still open at the moment.
msg199493 - (view) Author: W. Trevor King (labrat) * Date: 2013-10-11 17:35
On Fri, Oct 11, 2013 at 05:21:15PM +0000, Ned Deily wrote:
> This problem has been reported previously as Issue17354, a duplicate
> of Issue12853 which is still open at the moment.

Ah, I searched for a fwe possible subject lines, but didn't hit those
:p.  I thought that if it wasn't fixed in the master branch it must
not have an associated issue…

I like my patch better than Issue17354's, because PyPI servers may not
always use UTF-8.  I'll ping Issue12853 about the patches, because
either one would fix Issue12853, and it's currently "needs patch".
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63425
2013-10-11 17:35:35labratsetmessages: + msg199493
2013-10-11 17:21:15ned.deilysetstatus: open -> closed

superseder: global name 'r' is not defined in upload.py
versions: - Python 3.2, Python 3.5
nosy: + ned.deily

messages: + msg199492
resolution: duplicate
stage: resolved
2013-10-11 16:31:15labratcreate