Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnicodeDecodeError for httplib #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

moylop260
Copy link

@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