Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to update datasource of Picture element of layout element of a mapdocument. but it is showing Unicode decode error. mxd= arcpy.mapping.MapDocument("CURRENT") for elm in arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT"): oldname = ... if ..."ä","ae") ... print

after running the code I get following error message:

Runtime error Traceback (most recent call last): File "", line 4, in UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

share|improve this question
up vote 2 down vote accepted

I'm not an expert when it comes to dealing with unicode characters, but it looks like you need to do the replace using the unicode representation of the character "ä":"\xe4","ae")
share|improve this answer

I myself deal quite often with Unicode characters due to having different languages used for attributes storage within GIS datasets I handle. One of the techniques I've learnt regarding dealing with Unicode is that sometimes it is helpful to replace Unicode characters to the closest Latin one. This is particularly useful when you have two data sources and in one you have "Café" and in another "Cafe". This works fine for most diacritic symbols I've worked with, too.

You can for sure run replace on strings, but in case you need to automate this process and you don't want to end up creating a dictionary where keys=source symbols (ä) and values=the target symbols (ae), you can use this function.

import unicodedata

def strip_accents(s):
   return ''.join(c for c in unicodedata.normalize('NFD', s)
                  if unicodedata.category(c) != 'Mn')

str_input = u'\xe4' #your input string you get
print strip_accents(str_input)

More help information on Unicode in Python.

share|improve this answer

I prefer to use utf-8 throughout the script, encoding any strings where neccessary.

oldname ='utf-8')

It is also useful to declare the encoding at the top of each script.

# -*- coding: utf-8 -*-

See Alex's link to the Python Unicode page for more information.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.