Re: [求助]关于debian环境下通过M ySQLdb查询数据库时UnicodeDecodeError的 问题
"kongxiangbo 孔祥波" <[email protected]> Mon, 21 Jan 2008 17:39:42 +0800
| Newsgroups | gmane.comp.python.chinese |
|---|---|
| Message-ID | <[email protected]> |
首先确定你的.py文件的编码是不是utf-8,另外文件头需要code--utf-8 在 08-1-21,李李<[email protected]> 写道: > > 最近在写些操作mysql数据的东西,发现写出来后windows下运行正常,但只要迁到debian环境下就无法查询带有中文的数据库了; > > conn = MySQLdb.connect(host = host, db=db, user=user, > passwd=passwd, use_unicode=1, charset='utf8') > cursor = conn.cursor() > query = "select * from tab where su = '待'" > cursor.execute(query) > row1=cursor.fetchall() > > 错误信息: > File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 147, in execute > query = query.encode(charset) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb4 in position 35: ordinal not in range(128) > > > 各位高手,这个是为什么啊? > > > 也试过把 MySQLdb的cursor。execute改成 > def execute(self, query, char="utf-8", args=None): > charset = char > query = query.encode(charset) > > 最终还是不行,数据库切切实实是utf8的啊。 > > = = = = = = = = = = = = = = = = = = = = > > > 致 > 礼! > > > > > 李李 > 2008-01-21 > > > _______________________________________________ > python-chinese > Post: send [email protected] > Subscribe: send subscribe to [email protected] > Unsubscribe: send unsubscribe to [email protected] > Detail Info: http://python.cn/mailman/listinfo/python-chinese _______________________________________________ python-chinese Post: send [email protected] Subscribe: send subscribe to [email protected] Unsubscribe: send unsubscribe to [email protected] Detail Info: http://python.cn/mailman/listinfo/python-chinese