{"action":"created","issue":{"url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/2","labels_url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/2/comments","events_url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/2/events","html_url":"https://github.com/chfw/pyexcel-ods/issues/2","id":101418121,"number":2,"title":"Faulty unicode conversion when saving ods in environments with ASCII as default encoding","user":{"login":"felixring","id":13832538,"avatar_url":"https://avatars.githubusercontent.com/u/13832538?v=3","gravatar_id":"","url":"https://api.github.com/users/felixring","html_url":"https://github.com/felixring","followers_url":"https://api.github.com/users/felixring/followers","following_url":"https://api.github.com/users/felixring/following{/other_user}","gists_url":"https://api.github.com/users/felixring/gists{/gist_id}","starred_url":"https://api.github.com/users/felixring/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixring/subscriptions","organizations_url":"https://api.github.com/users/felixring/orgs","repos_url":"https://api.github.com/users/felixring/repos","events_url":"https://api.github.com/users/felixring/events{/privacy}","received_events_url":"https://api.github.com/users/felixring/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-17T13:13:22Z","updated_at":"2015-08-20T18:23:34Z","closed_at":"2015-08-19T21:45:37Z","body":"Hi,\r\n\r\nI ran into the beloved\r\n> UnicodeEncodeError: 'ascii' codec can't encode character u'\\xd6' in position 1: ordinal not in range(128)\r\n\r\nwhen saving data containing non ASCII characters to ods.\r\n\r\nPython 2.6.6 on CentOS 6, kernel  2.6.32-504.16.2.el6.x86_64\r\npyexcel version: 0.1.7\r\n\r\nA specific test code that triggers the problem is the following:\r\n```python\r\n#!/usr/bin/python\r\n# -*- encoding: utf-8 -*-\r\nimport pyexcel as pe\r\nfrom pyexcel.ext import ods\r\n\r\ndata = [[1,2,3],['Joe', unicode('DÖE', 'utf-8', 'strict'), 'Name']]\r\nmy_sheet = pe.Sheet(data)\r\nmy_sheet.save_as('test.ods')\r\n```\r\n\r\nA quick analysis showed that the type is recognized correctly, but somehow the conversion gets called twice when setting the attributes, once for the value-type, which specifies the type correctly as string, and then again for the value, which uses cnv_double, which breaks because of the non ASCII characters. I stopped debugging from there, as I would need a more thorough understanding of the employed conversion mechanisms.\r\n\r\nHere is the full traceback of the error:\r\n> Traceback (most recent call last):\r\n  File \"odstest.py\", line 8, in <module>\r\n    my_sheet.save_as('test.ods')\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel/sheets/sheet.py\", line 39, in save_as\r\n    return self.save_to(source)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel/sheets/sheet.py\", line 33, in save_to\r\n    source.write_data(self)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel/sources/file.py\", line 35, in write_data\r\n    w.write_reader(sheet)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel/writers.py\", line 75, in write_reader\r\n    self.write_rows(to_array(reader))\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel/writers.py\", line 45, in write_rows\r\n    self.writer.write_array(table)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel_io/base.py\", line 222, in write_array\r\n    self.write_row(r)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel_ods/__init__.py\", line 257, in write_row\r\n    self.write_cell(tr, x)\r\n  File \"/usr/lib/python2.6/site-packages/pyexcel_ods/__init__.py\", line 246, in write_cell\r\n    tc.setAttrNS(OFFICENS, x_odf_value_token, x)\r\n  File \"/usr/lib/python2.6/site-packages/odf/element.py\", line 440, in setAttrNS\r\n    self.attributes[(namespace, localpart)] = c.convert((namespace, localpart), value, self)\r\n  File \"/usr/lib/python2.6/site-packages/odf/attrconverters.py\", line 1489, in convert\r\n    return conversion(attribute, value, element)\r\n  File \"/usr/lib/python2.6/site-packages/odf/attrconverters.py\", line 77, in cnv_double\r\n    return str(arg)\r\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\xd6' in position 1: ordinal not in range(128)\r\n\r\nand here is the output of an added print statement in attrconverters.py:\r\n```python\r\nprint attribute, value, element\r\n```\r\n> (u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', u'mimetype') application/vnd.oasis.opendocument.spreadsheet\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', u'version') 1.1\r\n(u'urn:oasis:names:tc:opendocument:xmlns:table:1.0', u'name') pyexcel\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type') float\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value') 1\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type') float\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value') 2\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type') float\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value') 3\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type') string\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value') Joe\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value-type') string\r\n(u'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'value') DÖE\r\n\r\nI would greatly appreciate your help on solving this issue.\r\nThanks for the awesome package anyways.\r\n\r\nBest regards,\r\nFelix"},"comment":{"url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/comments/133108620","html_url":"https://github.com/chfw/pyexcel-ods/issues/2#issuecomment-133108620","issue_url":"https://api.github.com/repos/chfw/pyexcel-ods/issues/2","id":133108620,"user":{"login":"chfw","id":4280312,"avatar_url":"https://avatars.githubusercontent.com/u/4280312?v=3","gravatar_id":"","url":"https://api.github.com/users/chfw","html_url":"https://github.com/chfw","followers_url":"https://api.github.com/users/chfw/followers","following_url":"https://api.github.com/users/chfw/following{/other_user}","gists_url":"https://api.github.com/users/chfw/gists{/gist_id}","starred_url":"https://api.github.com/users/chfw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chfw/subscriptions","organizations_url":"https://api.github.com/users/chfw/orgs","repos_url":"https://api.github.com/users/chfw/repos","events_url":"https://api.github.com/users/chfw/events{/privacy}","received_events_url":"https://api.github.com/users/chfw/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T18:23:34Z","updated_at":"2015-08-20T18:23:34Z","body":"released to pypi as 0.0.9. pip shall be able to get it on fresh installation. for existing one, use the following commands:\r\n\r\n\r\n     pip install pyexcel-ods==0.0.9\r\n\r\nor\r\n\r\n    pip install --upgrade pyexcel-ods\r\n\r\nreopen this issue if it is not fixed for you."}}