smartsheet-platform / smartsheet-python-sdk

Library that uses Python to connect to Smartsheet services (using API 2.0).
Apache License 2.0
136 stars 81 forks source link

UnicodeEncodeError #43

Open josepham7 opened 8 years ago

josepham7 commented 8 years ago

The Python SDK doesn't support Unicode characters. Running a Get Sheet results in this error:

>>> sheet = smartsheet.Sheets.get_sheet(sheetId)

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/smartsheet/sheets.py", line 460, in get_sheet response = self._base.request(prepped_request, expected, _op) File "/usr/local/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 179, in request native = res.native(expected) File "/usr/local/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 408, in native obj = class_(data, self._base) File "/usr/local/lib/python2.7/site-packages/smartsheet/models/sheet.py", line 90, in __init__ self.columns = props['columns'] File "/usr/local/lib/python2.7/site-packages/smartsheet/models/sheet.py", line 220, in columns if not isinstance(x, Column) else x) for x in value File "/usr/local/lib/python2.7/site-packages/smartsheet/models/column.py", line 134, in __init__ self.options = props['options'] File "/usr/local/lib/python2.7/site-packages/smartsheet/models/column.py", line 257, in options if not isinstance(x, str) else x) for x in value UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128)

pensnarik commented 8 years ago

Have the same problem with Python 2.7.5.

[mutex@unica1 parser]$ ./update_region_price.py 
Traceback (most recent call last):
  File "./update_region_price.py", line 130, in <module>
    sys.exit(app.run(sys.argv))
  File "./update_region_price.py", line 123, in run
    self.update_basic()
  File "./update_region_price.py", line 66, in update_basic
    sheet = self.sm.Sheets.get_sheet(self.sheet_id, page_size=5000)
  File "/usr/lib/python2.7/site-packages/smartsheet/sheets.py", line 460, in get_sheet
    response = self._base.request(prepped_request, expected, _op)
  File "/usr/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 179, in request
    native = res.native(expected)
  File "/usr/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 408, in native
    obj = class_(data, self._base)
  File "/usr/lib/python2.7/site-packages/smartsheet/models/sheet.py", line 90, in __init__
    self.columns = props['columns']
  File "/usr/lib/python2.7/site-packages/smartsheet/models/sheet.py", line 220, in columns
    if not isinstance(x, Column) else x) for x in value
  File "/usr/lib/python2.7/site-packages/smartsheet/models/column.py", line 134, in __init__
    self.options = props['options']
  File "/usr/lib/python2.7/site-packages/smartsheet/models/column.py", line 257, in options
    if not isinstance(x, str) else x) for x in value
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-9: ordinal not in range(128)
timwellswa commented 7 years ago

I am going to defer this to a future date when we should look at all occurrences of non-ASCII text support through the API and whether they are being handled correctly. Since Python 2 and 3 handle unicode differently, this may not require much if support for python 2 is dropped.

anoronh4 commented 6 years ago

Was this ever resolved in python 2 or 3? I have installed this on python 2.7.9 and am running to this same error.

timwellswa commented 6 years ago

Nothing more has been done on this since my update last March. However, my understanding based on a short review then was that if you were using Python 3 no further modifications would be required. We are recommending 3.4 or higher if you need unicode support.