Re: Non-ASCII character

Pasithee Jupiter <[email protected]> Sat, 9 Apr 2011 20:17:19 +0200
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
--===============7755282099176692356==
Content-Type: multipart/alternative; boundary=000e0cd4ca4668d5b504a0805af0

--000e0cd4ca4668d5b504a0805af0
Content-Type: text/plain; charset=ISO-8859-1

I wrote the simplejson object in a file

values = simplejson.load(urllib.urlopen(urlvalue))

file.write(str(values))

and get some strange characters.

here an extract of the file

{'rp': 0, 'total': 15087, 'data': [{'count_all': 174518, 'key': 'amenity',
'value': 'restaurant'}, {'count_all': 161, 'key': 'bak:fac_type2', 'value':
'RESTAURANT'}, {'count_all': 155, 'key': 'wpt_symbol', 'value':
'Restaurant'}, {'count_all': 135, 'key': 'name', 'value': 'Restaurant'},
{'count_all': 124, 'key': 'kvl_hro:amenity', 'value': 'restaurant'},
{'count_all': 100, 'key': 'amenity', 'value': 'parking;restaurant;fuel'},
{'count_all': 69, 'key': 'building', 'value': 'restaurant'}, {'count_all':
69, 'key': 'name:en', 'value': 'Bada Fish Restaurant'}, {'count_all': 59,
'key': 'name:en', 'value': 'Busan Fish Restaurant'}, {'count_all': 57,
'key': 'arivac:typetxt', 'value': 'Eatery/Restaurant/Bakery/Coffee
shop'}, {'count_all':
56, 'key': 'name', 'value': u'\ubc14\ub2e4\ud69f\uc9d1 (Bada Fish
Restaurant)'}, {'count_all': 56, 'key': 'name:en', 'value': 'Donghae Fish
Restaurant'}, {'count_all': 45, 'key': 'name', 'value':
u'\ubd80\uc0b0\ud69f\uc9d1 (Busan Fish Restaurant)'}, {'count_all': 44,
'key': 'name', 'value': u'\ub3d9\ud574\ud69f\uc9d1 (Donghae Fish
Restaurant)'}, {'count_all': 41, 'key': 'name', 'value':
u'\ub0a8\ud574\ud69f\uc9d1 (Namhae Fish Restaurant)'}, {'count_all': 41,
'key': 'name:en', 'value': 'Namhae Fish Restaurant'}, {'count_all': 35,
'key': 'name:en', 'value': 'Deungdae Fish Restaurant'}, {'count_all': 34,
'key': 'building:use', 'value': 'restaurant'}, {'count_all': 33, 'key':
'garmin:description', 'value':

thanks a lot
pasithee


p.s.: sorry if you receive it twice. the attachment was too big



2011/4/9 R. Tyler Croy <[email protected]>

>
> On Sat, 09 Apr 2011, Pasithee Jupiter wrote:
>
> > Hi all
> >
> > I have the following error:
> > *<type 'exceptions.UnicodeEncodeError'>*: 'ascii' codec can't encode
> > character u'\xe4' in position 107216: ordinal not in range(128)
> >       args = ('ascii', u'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
> > Tra...</tbody>\n\t\t\t</table>\n\t\t</footer>\n\t</body>\n</html>',
> 107216,
> > 107217, 'ordinal not in range(128)')
> >       encoding = 'ascii'
> >       end = 107217
> >       message = ''
> >       object = u'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
> Tra...</tbody>
> > \n\t\t\t</table>\n\t\t</footer>\n\t</body>\n</html>'
> >       reason = 'ordinal not in range(128)'
> >       start = 107216
> >
> >
> > In my Python script I call a json url and get back a bunch of data:
> >
> > resultlist = simplejson.load(urllib.urlopen(urlvalue))
>
>
> What kind of object are you getting back from this simplejson call? If
> you're
> not getting a proper unicode object, you may need to do some decoding first
> to
> make the string play nicely with the rest of the template.
>
>
> That said, what version of Cheetah are you running?
>
> >
> > The url is the following:
> >
> http://taginfo.openstreetmap.de/api/2/search/values?q=restaurant&sortname=count_all&sortorder=desc
> >
> > As you can see when you open the url, the response includes a lot of
> special
> > characters
> > In my template I try to display these data which are in the resultlist
> > variable
> >
> > #for $result in $resultlist
> >
> > <tr>
> >
> > <td>$result['count']</td>
> >
> > <td>$result['key']</td>
> >
> > </tr>
> >
> > #end for
> >
> >
> > But it does not work.
> >
> >
> > Any hint?
> >
> > Thanks a lot
> >
> > Pasithee
>
> >
> ------------------------------------------------------------------------------
> > Xperia(TM) PLAY
> > It's a major breakthrough. An authentic gaming
> > smartphone on the nation's most reliable network.
> > And it wants your games.
> > http://p.sf.net/sfu/verizon-sfdev
>
> > _______________________________________________
> > Cheetahtemplate-discuss mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>
> - R. Tyler Croy
> --------------------------------------
>    Code: http://github.com/rtyler
>  Chatter: http://identi.ca/agentdero
>          http://twitter.com/agentdero
>

--000e0cd4ca4668d5b504a0805af0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<span class=3D"Apple-style-span" style=3D"font-family: arial, sans-serif; f=
ont-size: 13px; border-collapse: collapse; "><div>I wrote the simplejson ob=
ject in a file</div><blockquote style=3D"margin-top: 0px; margin-right: 0px=
; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-rig=
ht-style: none; border-bottom-style: none; border-left-style: none; border-=
width: initial; border-color: initial; padding-top: 0px; padding-right: 0px=
; padding-bottom: 0px; padding-left: 0px; ">
<div><p style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; ma=
rgin-left: 0px; font: normal normal normal 11px/normal Monaco; ">values =3D=
 simplejson.load(urllib.urlopen(urlvalue))</p></div><div><p style=3D"margin=
-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: n=
ormal normal normal 11px/normal Monaco; ">
</p><p style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; mar=
gin-left: 0px; font: normal normal normal 11px/normal Monaco; ">file.write(=
str(values))</p><p></p></div></blockquote>and get some strange characters.<=
div>
<br></div><div>here an extract of the file</div><div><br></div><div><font f=
ace=3D"&#39;times new roman&#39;, serif">{&#39;rp&#39;: 0, &#39;total&#39;:=
 15087, &#39;data&#39;: [{&#39;count_all&#39;: 174518, &#39;key&#39;: &#39;=
amenity&#39;, &#39;value&#39;: &#39;restaurant&#39;}, {&#39;count_all&#39;:=
 161, &#39;key&#39;: &#39;bak:fac_type2&#39;, &#39;value&#39;: &#39;RESTAUR=
ANT&#39;}, {&#39;count_all&#39;: 155, &#39;key&#39;: &#39;wpt_symbol&#39;, =
&#39;value&#39;: &#39;Restaurant&#39;}, {&#39;count_all&#39;: 135, &#39;key=
&#39;: &#39;name&#39;, &#39;value&#39;: &#39;Restaurant&#39;}, {&#39;count_=
all&#39;: 124, &#39;key&#39;: &#39;kvl_hro:amenity&#39;, &#39;value&#39;: &=
#39;restaurant&#39;}, {&#39;count_all&#39;: 100, &#39;key&#39;: &#39;amenit=
y&#39;, &#39;value&#39;: &#39;parking;restaurant;fuel&#39;}, {&#39;count_al=
l&#39;: 69, &#39;key&#39;: &#39;building&#39;, &#39;value&#39;: &#39;restau=
rant&#39;}, {&#39;count_all&#39;: 69, &#39;key&#39;: &#39;name:en&#39;, &#3=
9;value&#39;: &#39;Bada Fish Restaurant&#39;}, {&#39;count_all&#39;: 59, &#=
39;key&#39;: &#39;name:en&#39;, &#39;value&#39;: &#39;Busan Fish Restaurant=
&#39;}, {&#39;count_all&#39;: 57, &#39;key&#39;: &#39;arivac:typetxt&#39;, =
&#39;value&#39;: &#39;Eatery/Restaurant/Bakery/Coffee shop&#39;},=A0<span s=
tyle=3D"background-color: rgb(255, 255, 102); ">{&#39;count_all&#39;: 56, &=
#39;key&#39;: &#39;name&#39;, &#39;value&#39;: u&#39;\ubc14\ub2e4\ud69f\uc9=
d1 (Bada Fish Restaurant)&#39;}</span>, {&#39;count_all&#39;: 56, &#39;key&=
#39;: &#39;name:en&#39;, &#39;value&#39;: &#39;Donghae Fish Restaurant&#39;=
},=A0<span style=3D"background-color: rgb(255, 255, 102); ">{&#39;count_all=
&#39;: 45, &#39;key&#39;: &#39;name&#39;, &#39;value&#39;: u&#39;\ubd80\uc0=
b0\ud69f\uc9d1 (Busan Fish Restaurant)&#39;}</span>,=A0<span style=3D"backg=
round-color: rgb(255, 255, 102); ">{&#39;count_all&#39;: 44, &#39;key&#39;:=
 &#39;name&#39;, &#39;value&#39;: u&#39;\ub3d9\ud574\ud69f\uc9d1 (Donghae F=
ish Restaurant)&#39;}</span>,=A0<span style=3D"background-color: rgb(255, 2=
55, 102); ">{&#39;count_all&#39;: 41, &#39;key&#39;: &#39;name&#39;, &#39;v=
alue&#39;: u&#39;\ub0a8\ud574\ud69f\uc9d1 (Namhae Fish Restaurant)&#39;}</s=
pan>, {&#39;count_all&#39;: 41, &#39;key&#39;: &#39;name:en&#39;, &#39;valu=
e&#39;: &#39;Namhae Fish Restaurant&#39;}, {&#39;count_all&#39;: 35, &#39;k=
ey&#39;: &#39;name:en&#39;, &#39;value&#39;: &#39;Deungdae Fish Restaurant&=
#39;}, {&#39;count_all&#39;: 34, &#39;key&#39;: &#39;building:use&#39;, &#3=
9;value&#39;: &#39;restaurant&#39;}, {&#39;count_all&#39;: 33, &#39;key&#39=
;: &#39;garmin:description&#39;, &#39;value&#39;:=A0</font></div>
<div><br></div><div>thanks a lot</div><div>pasithee</div><div><br></div><di=
v><br></div><div>p.s.: sorry if you receive it twice. the attachment was to=
o big</div><div><br></div><div><br></div></span><br><div class=3D"gmail_quo=
te">
2011/4/9 R. Tyler Croy <span dir=3D"ltr">&lt;<a href=3D"mailto:tyler@monkey=
pox.org">[email protected]</a>&gt;</span><br><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x;">
<br>
On Sat, 09 Apr 2011, Pasithee Jupiter wrote:<br>
<br>
&gt; Hi all<br>
&gt;<br>
&gt; I have the following error:<br>
&gt; *&lt;type &#39;exceptions.UnicodeEncodeError&#39;&gt;*: &#39;ascii&#39=
; codec can&#39;t encode<br>
&gt; character u&#39;\xe4&#39; in position 107216: ordinal not in range(128=
)<br>
&gt; =A0 =A0 =A0 args =3D (&#39;ascii&#39;, u&#39;&lt;!DOCTYPE html PUBLIC =
&quot;-//W3C//DTD HTML 4.01<br>
&gt; Tra...&lt;/tbody&gt;\n\t\t\t&lt;/table&gt;\n\t\t&lt;/footer&gt;\n\t&lt=
;/body&gt;\n&lt;/html&gt;&#39;, 107216,<br>
&gt; 107217, &#39;ordinal not in range(128)&#39;)<br>
&gt; =A0 =A0 =A0 encoding =3D &#39;ascii&#39;<br>
&gt; =A0 =A0 =A0 end =3D 107217<br>
&gt; =A0 =A0 =A0 message =3D &#39;&#39;<br>
&gt; =A0 =A0 =A0 object =3D u&#39;&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DT=
D HTML 4.01 Tra...&lt;/tbody&gt;<br>
&gt; \n\t\t\t&lt;/table&gt;\n\t\t&lt;/footer&gt;\n\t&lt;/body&gt;\n&lt;/htm=
l&gt;&#39;<br>
&gt; =A0 =A0 =A0 reason =3D &#39;ordinal not in range(128)&#39;<br>
&gt; =A0 =A0 =A0 start =3D 107216<br>
&gt;<br>
&gt;<br>
&gt; In my Python script I call a json url and get back a bunch of data:<br=
>
&gt;<br>
&gt; resultlist =3D simplejson.load(urllib.urlopen(urlvalue))<br>
<br>
<br>
What kind of object are you getting back from this simplejson call? If you&=
#39;re<br>
not getting a proper unicode object, you may need to do some decoding first=
 to<br>
make the string play nicely with the rest of the template.<br>
<br>
<br>
That said, what version of Cheetah are you running?<br>
<br>
&gt;<br>
&gt; The url is the following:<br>
&gt; <a href=3D"http://taginfo.openstreetmap.de/api/2/search/values?q=3Dres=
taurant&amp;sortname=3Dcount_all&amp;sortorder=3Ddesc" target=3D"_blank">ht=
tp://taginfo.openstreetmap.de/api/2/search/values?q=3Drestaurant&amp;sortna=
me=3Dcount_all&amp;sortorder=3Ddesc</a><br>

&gt;<br>
&gt; As you can see when you open the url, the response includes a lot of s=
pecial<br>
&gt; characters<br>
&gt; In my template I try to display these data which are in the resultlist=
<br>
&gt; variable<br>
&gt;<br>
&gt; #for $result in $resultlist<br>
&gt;<br>
&gt; &lt;tr&gt;<br>
&gt;<br>
&gt; &lt;td&gt;$result[&#39;count&#39;]&lt;/td&gt;<br>
&gt;<br>
&gt; &lt;td&gt;$result[&#39;key&#39;]&lt;/td&gt;<br>
&gt;<br>
&gt; &lt;/tr&gt;<br>
&gt;<br>
&gt; #end for<br>
&gt;<br>
&gt;<br>
&gt; But it does not work.<br>
&gt;<br>
&gt;<br>
&gt; Any hint?<br>
&gt;<br>
&gt; Thanks a lot<br>
&gt;<br>
&gt; Pasithee<br>
<br>
&gt; ----------------------------------------------------------------------=
--------<br>
&gt; Xperia(TM) PLAY<br>
&gt; It&#39;s a major breakthrough. An authentic gaming<br>
&gt; smartphone on the nation&#39;s most reliable network.<br>
&gt; And it wants your games.<br>
&gt; <a href=3D"http://p.sf.net/sfu/verizon-sfdev" target=3D"_blank">http:/=
/p.sf.net/sfu/verizon-sfdev</a><br>
<br>
&gt; _______________________________________________<br>
&gt; Cheetahtemplate-discuss mailing list<br>
&gt; <a href=3D"mailto:[email protected]">Cheet=
[email protected]</a><br>
&gt; <a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplat=
e-discuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/c=
heetahtemplate-discuss</a><br>
<font color=3D"#888888"><br>
- R. Tyler Croy<br>
--------------------------------------<br>
 =A0 =A0Code: <a href=3D"http://github.com/rtyler" target=3D"_blank">http:/=
/github.com/rtyler</a><br>
=A0Chatter: <a href=3D"http://identi.ca/agentdero" target=3D"_blank">http:/=
/identi.ca/agentdero</a><br>
 =A0 =A0 =A0 =A0 =A0<a href=3D"http://twitter.com/agentdero" target=3D"_bla=
nk">http://twitter.com/agentdero</a><br>
</font></blockquote></div><br>

--000e0cd4ca4668d5b504a0805af0--


--===============7755282099176692356==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
--===============7755282099176692356==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

--===============7755282099176692356==--