unicode error & fix: cell.py
Created originally on Bitbucket by ericgazoni (Eric Gazoni)
Frank lorettax@gmail.com wrote:
Hi, I just had to figure out why I couldn't assign a string that I read straight from Oracle, to the "value" attribute of a cell.
Here's what happens:
{{{
print stringFromOracle Compound Price (£) someCell(someAddress).value = stringFromOracle
File "/usr/local/python/python2.7/lib/python2.7/site-packages/ openpyxl-1.5.3-py2.7.egg/openpyxl/cell.py", line 299, in _set_value self.bind_value(value) File "/usr/local/python/python2.7/lib/python2.7/site-packages/ openpyxl-1.5.3-py2.7.egg/openpyxl/cell.py", line 288, in bind_value self.set_value_explicit(value, self._data_type) File "/usr/local/python/python2.7/lib/python2.7/site-packages/ openpyxl-1.5.3-py2.7.egg/openpyxl/cell.py", line 218, in set_value_explicit self._value = type_coercion_mapdata_type File "/usr/local/python/python2.7/lib/python2.7/site-packages/ openpyxl-1.5.3-py2.7.egg/openpyxl/cell.py", line 190, in check_string value = unicode(value) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 16: ordinal not in range(128) }}}
The problem is calling unicode() without specifying an encoding. (e.g. http://boodebr.org/main/python/all-about-python-and-unicode)
line 190 should be: {{{ value = unicode(value, "utf-8") }}} to be safe.
Even better, allow encoding to be specified somewhere.