On Sun, Jun 2, 2013 at 4:18 PM, NP <[email protected]> wrote:
> Hello all,
>
> My datastore model has an attribute of class string. According to the
> documentation, the String class should be of type str or unicode.
>
> The data I'm trying to save is unicode (I confirmed this by printing out
> the type and the original page was encoded in utf-8).
>
> My data is successfully saved to the datastore but it still raises the
> following exception 'ascii' codec can't encode character u'\u2019' in
> position 6: ordinal not in range(128)
>
When does this exception happen? From the error message, you're trying to
encode u'\u2019' (RIGHT SINGLE QUOTATION MARK) with the 'ascii' codec. Here
is an example:
>>> u = u'\u2019'
>>> u.encode('ascii')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in
position 0: ordinal not in range(128)
>>> u.encode('utf-8') # you can get an utf-8 encoded binary string
'\xe2\x80\x99'
>
> I'm curious as to why an exception is being raised even though the data is
> unicode and why even with the exception, the data is still saved
> successfully.
>
> Apart from specifically trapping this error using something like
> {exception UnicodeEncodeError: pass}, is there a way to prevent this error?
>
I don't recommend doing that. I recommend you check where the exception
occurs and fix it.
-- Takashi
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-appengine?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
Takashi Matsuo | Developers Programs Engineer | [email protected]
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.