Loading ...
Sorry, an error occurred while loading the content.
 

[Cheetahtemplate-discuss] Non-ASCII character

Expand Messages
  • Pasithee Jupiter
    Hi all I have the following error: * *: ascii codec can t encode character u xe4 in position 107216: ordinal not in
    Message 1 of 3 , Apr 9, 2011
      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))


      The url is the following:

      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

    • R. Tyler Croy
      ... 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
      Message 2 of 3 , Apr 9, 2011
        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
        > Cheetahtemplate-discuss@...
        > 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
      • Pasithee Jupiter
        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
        Message 3 of 3 , Apr 9, 2011
          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 <tyler@...>

          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
          > Cheetahtemplate-discuss@...
          > 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

        Your message has been successfully submitted and would be delivered to recipients shortly.