[CPyUG] exceptions.UnicodeDecodeError: $ title = job.name_cn + job.name + '招聘'

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[CPyUG] exceptions.UnicodeDecodeError: $ title = job.name_cn + job.name + '招聘'

Ken-145
About web.py
--

$def with(job)
$ title = job.name_cn + job.name + '招聘'
$:render.header(title)

<type 'exceptions.UnicodeDecodeError'> at /jobs/detail-1
('ascii', "title = job.name_cn + job.name + '\xe6\x8b\x9b\xe8\x81\x98'", 34, 35, 'ordinal not in range(128)')

is this webpy's problem?
and I try to do like this:

        title = this_job.name_cn + this_job.name + '招聘'
        return render.job.view(this_job, title)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 56: ordinal not in range(128)

and then:
        title = this_job.name_cn + this_job.name + u'招聘'

It is OK.

why?
--
百才招聘(baicai.com).产品部
Email: [hidden email]
Gtalk: [hidden email]
twitter.com/qichangxing
http://blog.hi0791.com

--
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:[hidden email]
退订: http://tinyurl.com/45a9tb //针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: https://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
Reply | Threaded
Open this post in threaded view
|

Re: [CPyUG] exceptions.UnicodeDecodeError: $ title = job.name_cn + job.name + '招聘'

Wayne-39
你看一下 type(this_job.name_cn + this_job.name )的值是什么?应该是unicode。而 '招聘'是str,u'招聘'是unicode。所以会出现你遇到的问题
在python3k里面默认编码是unicode,这样的问题就会少很多。
2010/6/5 Ken <[hidden email]>
About web.py
--

$def with(job)
$ title = job.name_cn + job.name + '招聘'
$:render.header(title)

<type 'exceptions.UnicodeDecodeError'> at /jobs/detail-1
('ascii', "title = job.name_cn + job.name + '\xe6\x8b\x9b\xe8\x81\x98'", 34, 35, 'ordinal not in range(128)')

is this webpy's problem?
and I try to do like this:

        title = this_job.name_cn + this_job.name + '招聘'
        return render.job.view(this_job, title)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 56: ordinal not in range(128)

and then:
        title = this_job.name_cn + this_job.name + u'招聘'

It is OK.

why?
--
百才招聘(baicai.com).产品部
Email: [hidden email]
Gtalk: [hidden email]
twitter.com/qichangxing
http://blog.hi0791.com

--
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:[hidden email]
退订: http://tinyurl.com/45a9tb //针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: https://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp

--
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:[hidden email]
退订: http://tinyurl.com/45a9tb //针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: https://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
Reply | Threaded
Open this post in threaded view
|

Re: [CPyUG] exceptions.UnicodeDecodeError: $ title = job.name_cn + job.name + '招聘'

Ben Bear-2
In reply to this post by Ken-145
按照你的情景,建议把 '招聘' 替换成 unicode('招聘', 'utf-8')
$ title = job.name_cn + job.name + unicode('招聘', 'utf-8')

在 2010年6月5日 上午1:33,Ken <[hidden email]>写道:
About web.py
--

$def with(job)
$ title = job.name_cn + job.name + '招聘'
$:render.header(title)

<type 'exceptions.UnicodeDecodeError'> at /jobs/detail-1
('ascii', "title = job.name_cn + job.name + '\xe6\x8b\x9b\xe8\x81\x98'", 34, 35, 'ordinal not in range(128)')

is this webpy's problem?
and I try to do like this:

        title = this_job.name_cn + this_job.name + '招聘'
        return render.job.view(this_job, title)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 56: ordinal not in range(128)

and then:
        title = this_job.name_cn + this_job.name + u'招聘'

It is OK.

why?
--
百才招聘(baicai.com).产品部
Email: [hidden email]
Gtalk: [hidden email]
twitter.com/qichangxing
http://blog.hi0791.com

--
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:[hidden email]
退订: http://tinyurl.com/45a9tb //针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: https://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp

--
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:[hidden email]
退订: http://tinyurl.com/45a9tb //针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: https://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp