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"'times new roman', serif">{'rp': 0, 'total':=
15087, 'data': [{'count_all': 174518, 'key': '=
amenity', 'value': 'restaurant'}, {'count_all':=
161, 'key': 'bak:fac_type2', 'value': 'RESTAUR=
ANT'}, {'count_all': 155, 'key': 'wpt_symbol', =
'value': 'Restaurant'}, {'count_all': 135, 'key=
': 'name', 'value': 'Restaurant'}, {'count_=
all': 124, 'key': 'kvl_hro:amenity', 'value': &=
#39;restaurant'}, {'count_all': 100, 'key': 'amenit=
y', 'value': 'parking;restaurant;fuel'}, {'count_al=
l': 69, 'key': 'building', 'value': 'restau=
rant'}, {'count_all': 69, 'key': 'name:en', =
9;value': 'Bada Fish Restaurant'}, {'count_all': 59, &#=
39;key': 'name:en', 'value': 'Busan Fish Restaurant=
'}, {'count_all': 57, 'key': 'arivac:typetxt', =
'value': 'Eatery/Restaurant/Bakery/Coffee shop'},=A0<span s=
tyle=3D"background-color: rgb(255, 255, 102); ">{'count_all': 56, &=
#39;key': 'name', 'value': u'\ubc14\ub2e4\ud69f\uc9=
d1 (Bada Fish Restaurant)'}</span>, {'count_all': 56, 'key&=
#39;: 'name:en', 'value': 'Donghae Fish Restaurant'=
},=A0<span style=3D"background-color: rgb(255, 255, 102); ">{'count_all=
': 45, 'key': 'name', 'value': u'\ubd80\uc0=
b0\ud69f\uc9d1 (Busan Fish Restaurant)'}</span>,=A0<span style=3D"backg=
round-color: rgb(255, 255, 102); ">{'count_all': 44, 'key':=
'name', 'value': u'\ub3d9\ud574\ud69f\uc9d1 (Donghae F=
ish Restaurant)'}</span>,=A0<span style=3D"background-color: rgb(255, 2=
55, 102); ">{'count_all': 41, 'key': 'name', 'v=
alue': u'\ub0a8\ud574\ud69f\uc9d1 (Namhae Fish Restaurant)'}</s=
pan>, {'count_all': 41, 'key': 'name:en', 'valu=
e': 'Namhae Fish Restaurant'}, {'count_all': 35, 'k=
ey': 'name:en', 'value': 'Deungdae Fish Restaurant&=
#39;}, {'count_all': 34, 'key': 'building:use', =
9;value': 'restaurant'}, {'count_all': 33, 'key'=
;: 'garmin:description', 'value':=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"><<a href=3D"mailto:tyler@monkey=
pox.org">[email protected]</a>></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>
> Hi all<br>
><br>
> I have the following error:<br>
> *<type 'exceptions.UnicodeEncodeError'>*: 'ascii'=
; codec can't encode<br>
> character u'\xe4' in position 107216: ordinal not in range(128=
)<br>
> =A0 =A0 =A0 args =3D ('ascii', u'<!DOCTYPE html PUBLIC =
"-//W3C//DTD HTML 4.01<br>
> Tra...</tbody>\n\t\t\t</table>\n\t\t</footer>\n\t<=
;/body>\n</html>', 107216,<br>
> 107217, 'ordinal not in range(128)')<br>
> =A0 =A0 =A0 encoding =3D 'ascii'<br>
> =A0 =A0 =A0 end =3D 107217<br>
> =A0 =A0 =A0 message =3D ''<br>
> =A0 =A0 =A0 object =3D u'<!DOCTYPE html PUBLIC "-//W3C//DT=
D HTML 4.01 Tra...</tbody><br>
> \n\t\t\t</table>\n\t\t</footer>\n\t</body>\n</htm=
l>'<br>
> =A0 =A0 =A0 reason =3D 'ordinal not in range(128)'<br>
> =A0 =A0 =A0 start =3D 107216<br>
><br>
><br>
> In my Python script I call a json url and get back a bunch of data:<br=
>
><br>
> 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>
><br>
> The url is the following:<br>
> <a href=3D"http://taginfo.openstreetmap.de/api/2/search/values?q=3Dres=
taurant&sortname=3Dcount_all&sortorder=3Ddesc" target=3D"_blank">ht=
tp://taginfo.openstreetmap.de/api/2/search/values?q=3Drestaurant&sortna=
me=3Dcount_all&sortorder=3Ddesc</a><br>
><br>
> As you can see when you open the url, the response includes a lot of s=
pecial<br>
> characters<br>
> In my template I try to display these data which are in the resultlist=
<br>
> variable<br>
><br>
> #for $result in $resultlist<br>
><br>
> <tr><br>
><br>
> <td>$result['count']</td><br>
><br>
> <td>$result['key']</td><br>
><br>
> </tr><br>
><br>
> #end for<br>
><br>
><br>
> But it does not work.<br>
><br>
><br>
> Any hint?<br>
><br>
> Thanks a lot<br>
><br>
> Pasithee<br>
<br>
> ----------------------------------------------------------------------=
--------<br>
> Xperia(TM) PLAY<br>
> It's a major breakthrough. An authentic gaming<br>
> smartphone on the nation's most reliable network.<br>
> And it wants your games.<br>
> <a href=3D"http://p.sf.net/sfu/verizon-sfdev" target=3D"_blank">http:/=
/p.sf.net/sfu/verizon-sfdev</a><br>
<br>
> _______________________________________________<br>
> Cheetahtemplate-discuss mailing list<br>
> <a href=3D"mailto:[email protected]">Cheet=
[email protected]</a><br>
> <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==--