Python论坛  - 讨论区

标题:[python-chinese] ENCODING PROBLEM when using MySQLdb :(

2006年07月01日 星期六 10:35

jin yi jinyi at nlsde.buaa.edu.cn
Sat Jul 1 10:35:24 HKT 2006

For my system has no chinese input, so it is a english mail:(

I want to use MySQLdb to access mysql database, a part of my code is
below: 
============================================================================== 
# connect database using root 
try: 
db = MySQLdb.connect(host='localhost',user='root',passwd='appla141620') 
except: 
print 'Fail to connect database:',dbparam[0],',',dbparam[1] 
sys.exit(-1) 
# create database 
c = db.cursor() 
c.execute("create database if not exists " + dbparam[4]) 
c.close() 
db.commit() 
db.close() 
sys.exit(-1) 
============================================================================== 
when it runs to c.execute("......"), a exception is raised: 

Traceback (most recent call last): 
File "./builddb.py", line 101, in ? 
c.execute("create database if not exists " + dbparam[4]) 
File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 146, in
execute 
query = query.encode(charset) 
LookupError: unknown encoding: latin1_swedish_ci 
============================================================================== 
the softwares are: 
redhat-fedora-c3 
MySQL 4.1.20-standard 
MySQL-python-1.2.1_p2 
Python 2.3.4 (#1, Feb 2 2005, 12:11:53) [GCC 3.4.2 20041017 (Red Hat
3.4.2-6.fc3)] on linux2 
============================================================================== 
It maybe a small problem, I have searched many materials, but have not
solved it yet, 
desire your help and thanks all very much.

best regards
jinyi
2006/07/01


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号