[gdal-dev] Are unicode field values supported in the Python bindings for GDAL?

Paolo Corti pcorti at gmail.com
Wed Apr 11 08:02:11 EDT 2012


On Wed, Apr 11, 2012 at 12:43 PM, Roy Hyunjin Han
<starsareblueandfaraway at gmail.com> wrote:
>
>    WORD = 'Спасибо'.decode('utf-8')
>
>    # UnicodeEncodeError: 'ascii' codec can't encode characters in
> position 0-6: ordinal not in range(128)
>
>    WORD = 'Спасибо'.decode('utf-8')
>
>    # Some characters cannot be converted to latin-1
>    WORD.encode('latin-1')
>    # UnicodeEncodeError: 'latin-1' codec can't encode characters in
> position 0-6: ordinal not in range(256)

Not sure what you are trying to do, and pretty sure that this is
definitely obvious for you and not related at all to GDAL, but it
seems to me that you are trying to encode in latin1 and ascii a string
that contains characters not present in those encodings:

>>> 'Спасибо'.encode('ascii')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position
0: ordinal not in range(128)
>>> 'Спасибо'.encode('latin-1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position
0: ordinal not in range(128)
>>> 'simple characters'.encode('ascii')
'simple characters'
>>> 'simple characters'.encode('latin-1')
'simple characters'

p

-- 
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @capooti
skype: capooti


More information about the gdal-dev mailing list