Skip to content

Fix UnicodeDecodeError for httplib#144

Open
moylop260 wants to merge 2 commits intotransifex:masterfrom
moylop260:master-fix-unicode-url-moy
Open

Fix UnicodeDecodeError for httplib#144
moylop260 wants to merge 2 commits intotransifex:masterfrom
moylop260:master-fix-unicode-url-moy

Conversation

@moylop260
Copy link
Copy Markdown

@moylop260 moylop260 commented Nov 24, 2016

Python 2.7.6 - /usr/lib/python2.7/httplib.py has the following code:

 820   def _send_output(self, message_body=None):
 821          """Send the currently buffered request and clear the buffer..."""
 826         self._buffer.extend(("", ""))
 827         msg = "\r\n".join(self._buffer)
 828         del self._buffer[:]
 829         # If msg and message_body are sent in a single send() call,
 830         # it will avoid performance problems caused by the interaction
 831         # between delayed ack and the Nagle algorithm.
 832         if isinstance(message_body, str):
 833             msg += message_body
 834             message_body = None
 835         self.send(msg)

If the variable self._buffer (line 827) has
[u'PUT /api/2/project/PROJECT/resource/RESOURCE/content/ HTTP/1.1', ...]
then msg variable is unicode string
but message_body is bytes string (line 832)
The line 833 concatenate unicode + bytes string and show the error:
Fix UnicodeDecodeError: 'ascii' codec can't decode byte ... in position ...: ordinal not in range(128)

Similar to:
python -c "u'unicode string' + 'bytes string é'"

Traceback (most recent call last):
  File "<input>", line 1, in <module>
    u'unicode string' + 'bytes string é'
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128)

It's fixed forcing in host and url variables of transifex-client use bytes to concatenate bytes vs bytes.

Note: We are using from __future__ import unicode_literals

Python 2.7.6 - /usr/lib/python2.7/httplib.py
 820 def _send_output(self, message_body=None):
 821         Send the currently buffered request and clear the buffer. ---------------------------------------- 4--
 826         self._buffer.extend(("", ""))
 827         msg = "\r\n".join(self._buffer)
 828         del self._buffer[:]
 829         # If msg and message_body are sent in a single send() call,
 830         # it will avoid performance problems caused by the interaction
 831         # between delayed ack and the Nagle algorithm.
 832         if isinstance(message_body, str):
 833             msg += message_body
 834             message_body = None
 835         self.send(msg)

If the variable `self._buffer` has
[u'PUT /api/2/project/PROJECT/resource/RESOURCE/content/ HTTP/1.1', ...]
`msg` is unicode string
`message_body` is bytes string
The line 833 concatenate unicode + bytes string and show the error:
`Fix UnicodeDecodeError: 'ascii' codec can't decode byte ... in position ...: ordinal not in range(128)`

This could be fixed if we force in `host` and `url` of transifex-client use bytes to concatenate bytes vs bytes
moylop260 added a commit to vauxoo-dev/maintainer-quality-tools that referenced this pull request Nov 24, 2016
moylop260 added a commit to Vauxoo/maintainer-quality-tools that referenced this pull request Nov 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant