[py3] bug.addAttachment() causes UnicodeEncodeError with binary data

Bug #1414063 reported by Martin Pitt on 2015-01-23
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restfulclient (Ubuntu)
Dimitri John Ledkov
python-wadllib (Ubuntu)

Bug Description

While porting Apport to python3-launchpadlib, I stumbled over the inability to attach binary data to a bug:

$ python3 /tmp/test.py
Traceback (most recent call last):
  File "/tmp/test.py", line 15, in <module>
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 609, in __call__
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 385, in _request
    str(url), method=method, body=data, headers=headers)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 355, in _request_and_retry
    url, method=method, body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1291, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 131, in _request
    LaunchpadOAuthAwareHttp, self)._request(*args)
  File "/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py", line 183, in _request
    redirections, cachekey)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 1041, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python3/dist-packages/httplib2/__init__.py", line 966, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1127, in _send_request
    body = body.encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1217-1218: ordinal not in range(256)

When I call the same with python 2, it works fine. Note that this is a write operation, so this needs to use login_with() and credentials. So you might want to change the credentials_file= argument in the reproducer or drop it completely (then you'll have to log in every time you run the reproducer).

Martin Pitt (pitti) wrote :
Martin Pitt (pitti) on 2015-01-23
summary: - bug.addAttachment() causes UnicodeEncodeError with binary data
+ [py3] bug.addAttachment() causes UnicodeEncodeError with binary data
Changed in lazr.restfulclient (Ubuntu):
assignee: nobody → Dimitri John Ledkov (xnox)
Changed in lazr.restfulclient (Ubuntu):
status: New → In Progress

some attachment

Dimitri John Ledkov (xnox) wrote :

some attachment

Dimitri John Ledkov (xnox) wrote :

Hm, not good, i'm double encoding binary data here.....

Dimitri John Ledkov (xnox) wrote :

some attachment

Changed in lazr.restfulclient (Ubuntu):
status: In Progress → Triaged
Changed in python-wadllib (Ubuntu):
status: New → Confirmed
Dimitri John Ledkov (xnox) wrote :

I will have to raise python3 requirement to 3.4.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package python-wadllib - 1.3.2-3

python-wadllib (1.3.2-3) unstable; urgency=medium

  * Return binary MIME representation, rather than string. (LP: #1414063)
  * Bump python3 compat to 3.4.
  * Bump standards version to 3.9.6.

 -- Dimitri John Ledkov <email address hidden> Wed, 11 Feb 2015 04:34:50 +0000

Changed in python-wadllib (Ubuntu):
status: Confirmed → Fix Released
Changed in lazr.restfulclient (Ubuntu):
status: Triaged → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers