title: How to solve a UnicodeDecodeError?
body: <p>I get a strange error message when trying to read non-ascii from the datastore:</p>
  
  <pre><code>'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)
  Traceback (most recent call last):
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1511, in __call__
      rv = self.handle_exception(request, response, e)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1505, in __call__
      rv = self.router.dispatch(request, response)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1253, in default_dispatcher
      return route.handler_adapter(request, response)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1077, in __call__
      return handler.dispatch()
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/handler.py", line 127, in dispatch
      response = super(NewBaseHandler, self).dispatch()
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 547, in dispatch
      return self.handle_exception(e, self.app.debug)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 545, in dispatch
      return method(*args, **kwargs)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/handler.py", line 73, in check_login
      return handler(self, *args, **kwargs)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/handler.py", line 526, in get
      user=user)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/handler.py", line 91, in render_jinja
      **template_args))
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2_extras/jinja2.py", line 158, in render_template
      return self.environment.get_template(_filename).render(**context)
    File "/base/data/home/apps/s~myapp-www/events.355951895377615944/jinja2/environment.py", line 894, in render
      return self.environment.handle_exception(exc_info, True)
    File "template_files/my_organization.html", line 148, in top-level template code
      &lt;li id="{{ person.key.id()|makeid }}" class="level_1 inactive   leaf"&gt;&lt;a href="" style="" class=""&gt;&lt;ins&gt;&amp;nbsp;&lt;/ins&gt;&lt;table class="leaf_info"&gt;&lt;tbody&gt;    &lt;tr&gt;&lt;td class="name"&gt;{{ person.firstname }} {{ person.lastname}} {{person.key.id()|makeid}}&lt;/td&gt;&lt;td class="level" title="New Distributor"&gt;&lt;span class="level_parseable"&gt;1&lt;/span&gt;1&lt;/td&gt;&lt;td class="downlines"&gt;0&lt;/td&gt;&lt;td class="cc_personal"&gt;&lt;span class="cc_personal_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_downlines"&gt;&lt;span class="cc_downlines_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_activity"&gt;&lt;span class="cc_activity_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_nonmanager"&gt;&lt;span class="cc_nonmanager_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_total"&gt;&lt;span class="cc_total_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/a&gt;&lt;/li&gt;{% endfor %}
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)
  </code></pre>
  
  <p>The loop that used to work is ordinary:</p>
  
  <pre><code>{% for person in people %}
      &lt;li id="{{ person.key.id()|makeid }}" class="level_1 inactive   leaf"&gt;
  &lt;a href="" style="" class=""&gt;&lt;ins&gt;&amp;nbsp;&lt;/ins&gt;&lt;table class="leaf_info"&gt;&lt;tbody&gt;  &lt;tr&gt;&lt;td class="name"&gt;{{ person.firstname }} {{ person.lastname}} {{person.key.id()|makeid}}&lt;/td&gt;&lt;td class="level" title="New Distributor"&gt;&lt;span class="level_parseable"&gt;1&lt;/span&gt;1&lt;/td&gt;&lt;td class="downlines"&gt;0&lt;/td&gt;&lt;td class="cc_personal"&gt;&lt;span class="cc_personal_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_downlines"&gt;&lt;span class="cc_downlines_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_activity"&gt;&lt;span class="cc_activity_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_nonmanager"&gt;&lt;span class="cc_nonmanager_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;td class="cc_total"&gt;&lt;span class="cc_total_parseable"&gt;&lt;/span&gt;0&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>What can I do to resolve this error?</p>
  
  <p>My handler looks like this</p>
  
  <pre><code>class Myorg(NewBaseHandler):
      @user_required
      def get(self):
          user = auth_models.User.get_by_id(long(self.auth.get_user_by_session()['user_id']))
          people = auth_models.User.query(auth_models.User.sponsor == user.key).fetch()
          self.render_jinja('my_organization.html', people=people,
                                user=user)
  </code></pre>
  
  <p>And my model definition is the User model from webapp2. Here is also my custom filer makeid:</p>
  
  <pre><code>def makeid(n, countrycode="46"):
      countrycode = str(countrycode)
      n = str(n)
      return "%s%s%s" % (countrycode, '0'*(12-len(countrycode)-len(n)), n)
  </code></pre>
  
  <h2>Update</h2>
  
  <p>The workaround is strange, I just make a <code>.decode('utf-8')</code> which is shouldn't need to be doing:</p>
  
  <pre><code>class UpdateHandler(NewBaseHandler):
  
      @user_required
      def get(self):
          user = \
              auth_models.User.get_by_id(long(self.auth.get_user_by_session()['user_id'
                  ]))
          sponsor = None
          if user.sponsor:
              sponsor = user.sponsor.get()
          address = None
          if user.address:
              address = user.address.decode('utf-8')
          if user.city:
              city = user.city.decode('utf-8')
          self.render_jinja('details.html', city=city, user=user, address=address, sponsor=sponsor, form=UpdateForm(obj=user))
  </code></pre>
  
  <p>Is there any way to decode the all of the variables of the user object at once instead of one by one?</p>