[Help]UnicodeDecodeError

Discussion in 'Python' started by Karl, Mar 18, 2007.

  1. Karl

    Karl Guest

    error msg:
    Mod_python error: "PythonHandler mod_python.publisher"

    Traceback (most recent call last):

    File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
    299, in HandlerDispatch
    result = object(req)

    File "/usr/lib/python2.3/site-packages/mod_python/publisher.py",
    line 136, in handler
    result = util.apply_fs_data(object, req.form, req=req)

    File "/usr/lib/python2.3/site-packages/mod_python/util.py", line
    361, in apply_fs_data
    return object(**args)

    File "/var/www/html/sky.py", line 38, in main
    sresult = sresult.decode('zh-hk').encode('utf_8')

    UnicodeDecodeError: 'big5hkscs' codec can't decode bytes in position
    958-959: illegal multibyte sequence


    Wt can I do, since there is some characters, is there any solutions to
    solve it???

    thx
    Karl, Mar 18, 2007
    #1
    1. Advertising

  2. Karl

    Peter Otten Guest

    Karl wrote:

    > error msg:
    > Mod_python error: "PythonHandler mod_python.publisher"
    >
    > Traceback (most recent call last):
    >
    > File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
    > 299, in HandlerDispatch
    > result = object(req)
    >
    > File "/usr/lib/python2.3/site-packages/mod_python/publisher.py",
    > line 136, in handler
    > result = util.apply_fs_data(object, req.form, req=req)
    >
    > File "/usr/lib/python2.3/site-packages/mod_python/util.py", line
    > 361, in apply_fs_data
    > return object(**args)
    >
    > File "/var/www/html/sky.py", line 38, in main
    > sresult = sresult.decode('zh-hk').encode('utf_8')
    >
    > UnicodeDecodeError: 'big5hkscs' codec can't decode bytes in position
    > 958-959: illegal multibyte sequence
    >
    >
    > Wt can I do, since there is some characters, is there any solutions to
    > solve it???


    Other than requiring valid input?
    You can choose a more lenient decoding strategy, e. g.:

    sresult = sresult.decode('zh-hk', "replace")

    >>> help(s.decode)

    Help on built-in function decode:

    decode(...)
    S.decode([encoding[,errors]]) -> object

    Decodes S using the codec registered for encoding. encoding defaults
    to the default encoding. errors may be given to set a different error
    handling scheme. Default is 'strict' meaning that encoding errors raise
    a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
    as well as any other name registerd with codecs.register_error that is
    able to handle UnicodeDecodeErrors.

    Peter
    Peter Otten, Mar 18, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ruslan
    Replies:
    1
    Views:
    498
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 7, 2004
  2. Robin Siebler
    Replies:
    4
    Views:
    26,111
    Tim Peters
    Oct 8, 2004
  3. Thomas Thomas

    UnicodeDecodeError

    Thomas Thomas, May 5, 2005, in forum: Python
    Replies:
    2
    Views:
    311
    Michael Spencer
    May 5, 2005
  4. F. GEIGER
    Replies:
    0
    Views:
    1,571
    F. GEIGER
    May 27, 2005
  5. Robin Haswell

    UnicodeDecodeError help please?

    Robin Haswell, Apr 7, 2006, in forum: Python
    Replies:
    4
    Views:
    8,960
    Ben C
    Apr 7, 2006
Loading...

Share This Page