Issue #14 resolved

non-ascii filenames cause UnicodeDecodeError

Kumar McMillan
created an issue

The filename in question was {{{Tom Zé/Estudando A Bossa Nordeste Plaza/11 Amor Do Rio (part. Zélia Duncan).mp3}}}

{{{ Traceback (most recent call last): ... File "", line 125, in upload data, headers = multipart_encode(params) File "/Users/kumar/Envs/rockitlib/lib/python2.6/site-packages/poster/", line 411, in multipart_encode headers = get_headers(params, boundary) File "/Users/kumar/Envs/rockitlib/lib/python2.6/site-packages/poster/", line 311, in get_headers headers['Content-Length'] = str(get_body_size(params, boundary)) File "/Users/kumar/Envs/rockitlib/lib/python2.6/site-packages/poster/", line 302, in get_body_size size = sum(p.get_size(boundary) for p in MultipartParam.from_params(params)) File "/Users/kumar/Envs/rockitlib/lib/python2.6/site-packages/poster/", line 177, in from_params filetype=filetype, fileobj=value)) File "/Users/kumar/Envs/rockitlib/lib/python2.6/site-packages/poster/", line 84, in init = Header(name).encode() File "/usr/local/Cellar/python2.6/2.6.5/lib/python2.6/email/", line 176, in init self.append(s, charset, errors) File "/usr/local/Cellar/python2.6/2.6.5/lib/python2.6/email/", line 260, in append ustr = unicode(s, incodec, errors) UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 51: ordinal not in range(128) }}}

This line can probably be changed to {{{ = Header(name).encode('utf8')}}} but maybe a {{{content-type; charset: utf8}}} header should be added

Comments (1)

  1. Kumar McMillan reporter

    Ah! I needed unicode filenames. This was the fix I needed:

        # Ensure file is Unicode:
        filename = filename.decode(sys.getfilesystemencoding())
        with open(filename, 'rb') as fp:
             params = {filename: fp}
             data, headers = multipart_encode(params)
  2. Log in to comment