Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
疯了疯了…… 'ascii' codec can't decode byte ……
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
est  
View profile   Translate to Translated (View Original)
 More options Feb 27 2008, 12:56 pm
From: est <electronix...@gmail.com>
Date: Wed, 27 Feb 2008 09:56:38 -0800 (PST)
Local: Wed, Feb 27 2008 12:56 pm
Subject: 疯了疯了…… 'ascii' codec can't decode byte ……
弄了一个晚上,最终被Python+MySQL的编码搞崩溃了
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position
108: ordinal not in range(128)

我觉得python编码问题的主要原因是:
1. 默认的ascii不支持 \x128 - \x255 不可见字符的解析
2. 字串、unicode对象 和 byte array  三者的混淆(各种模块里标准不一样,造成兼容性问题)

我觉得这个问题应该这样解决:

1. 字符串类型仍然为sequence,但是一个字符串是一个unicode char,一个字符串对象可以有编码。但是一个中文和一个英文字母长度
都应该是1

2. 字符串和byte arrary区分开来。保证byte array不会出现编码问题

最后弱弱的问一下:在哪里可以修改ascii的codec?我准备把这个codec做个手术,把范围扩大到range(0, 255)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jiahua Huang  
View profile   Translate to Translated (View Original)
 More options Feb 27 2008, 5:19 pm
From: "Jiahua Huang" <jhuangjia...@gmail.com>
Date: Thu, 28 Feb 2008 06:19:44 +0800
Local: Wed, Feb 27 2008 5:19 pm
Subject: Re: [CPyUG:41527] 疯了疯了…… 'ascii' codec can't decode byte ……
是你的问题。你自己混淆了 python2 里边的 str 和 unicode 数据类型。
你的解决思路也是错的。

请贴出问题代码

btw:
0.
你需要的是让编码用实际编码而不是 ascii

1.
对需要 str->unicode 的代码,可以在前边写上
import sys
reload(sys)
sys.setdefaultencoding('utf8')
把 str 编码由 ascii 改为 utf8 (或 gb18030)

2.
python3 区分了 unicode str 和 byte arrary,并且默认编码不再是 ascii

2008/2/28 est <electronix...@gmail.com>:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zoom. Quiet  
View profile   Translate to Translated (View Original)
 More options Feb 27 2008, 7:50 pm
From: Zoom.Quiet <zoom.qu...@gmail.com>
Date: Thu, 28 Feb 2008 08:50:35 +0800
Local: Wed, Feb 27 2008 7:50 pm
Subject: Re: [CPyUG:41528] Re: 疯了疯了…… 'ascii' codec can't decode byte ……
提醒你的DB模块提供控制MySQL 输出编码?
MySQL 4.0 之后对编码进行了加强,
如果你配置DB/表/字段的编码都是 utf-8 ,而且聲明以UTF-8 的编码进行连接,
基本上Py 操作,没有任何问题

2008/2/28 Jiahua Huang <jhuangjia...@gmail.com>:

--
'''Time is unimportant, only life important!
过程改进乃是开始催生可促生靠谱的人的组织!
'''http://zoomquiet.org
博 @ http://blog.zoomquiet.org/pyblosxom/
维 @ http://wiki.woodpecker.org.cn/moin/ZoomQuiet
豆 @ http://www.douban.com/people/zoomq/
看 @ http://zoomq.haokanbu.com/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip.  http://7-zip.org
You can get the truely Freedom 4 software.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
OnMyWay  
View profile   Translate to Translated (View Original)
 More options Feb 27 2008, 10:47 pm
From: OnMyWay <onmywa...@gmail.com>
Date: Thu, 28 Feb 2008 11:47:46 +0800
Local: Wed, Feb 27 2008 10:47 pm
Subject: Re: [CPyUG:41532] Re: 疯了疯了…… 'ascii' codec can't decode byte ……
在postgresql上出现过类似问题,应该是数据库的编码问题。检查一下哪里可以设置client encoding.

在 08-2-28,Zoom. Quiet<zoom.qu...@gmail.com> 写道:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
est  
View profile   Translate to Translated (View Original)
 More options Feb 28 2008, 12:05 am
From: est <electronix...@gmail.com>
Date: Wed, 27 Feb 2008 21:05:08 -0800 (PST)
Local: Thurs, Feb 28 2008 12:05 am
Subject: Re: 疯了疯了…… 'ascii' codec can't decode byte ……
谢谢解答啊。

我的mysql服务器、表、python文件、代码内部编码都是用的utf-8。但是要写入的数据来源有点混乱,有gb2312的网页也有utf8的网
页……解析之后格式化字符串的时候一堆问题……

我已经搞定了,的确是str和unicode类型的混淆使用类型,统一encode一次就OK了。

非常期待py3k,希望能够解决编码问题

痛苦……

On 2月28日, 上午6时19分, "Jiahua Huang" <jhuangjia...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
yuting cui  
View profile   Translate to Translated (View Original)
 More options Feb 28 2008, 12:34 am
From: "yuting cui" <yuting...@gmail.com>
Date: Thu, 28 Feb 2008 13:34:59 +0800
Local: Thurs, Feb 28 2008 12:34 am
Subject: Re: [CPyUG:41566] Re: 疯了疯了…… 'ascii' codec can't decode byte ……
这种编码混乱出的错用什么都一样...
...不报错硬给你塞才是噩梦...最后用的时候才发现一堆乱码,还不知道哪里出的错

在 08-2-28,est<electronix...@gmail.com> 写道:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jigloo  
View profile   Translate to Translated (View Original)
 More options Feb 28 2008, 1:27 am
From: jigloo <p...@live.com>
Date: Wed, 27 Feb 2008 22:27:08 -0800 (PST)
Local: Thurs, Feb 28 2008 1:27 am
Subject: Re: 疯了疯了…… 'ascii' codec can't decode byte ……
到zhuaxia搜一下,有篇文章讲的py+mysql十分详细。

On 2月28日, 下午1时05分, est <electronix...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
man lo  
View profile   Translate to Translated (View Original)
 More options Feb 28 2008, 1:41 am
From: "man lo" <loman...@gmail.com>
Date: Thu, 28 Feb 2008 14:41:50 +0800
Local: Thurs, Feb 28 2008 1:41 am
Subject: Re: [CPyUG:41581] Re: 疯了疯了…… 'ascii' codec can't decode byte ……

这个解决应该还是很简单、、、、

首先看下你的数据库的编码格式。。。

如是UTF-8的   一般我的解决方法是 源文件 和数据库的编码要保持一致

然后对插入数据库中的中文出现问题的话  一般 decode某一编码 再encode成目标编码.....

在08-2-28,jigloo <p...@live.com> 写道:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google