Encodign issue in Python 3.3.1 (once again)

Michael Torrie torriem at gmail.com
Tue May 28 12:40:09 EDT 2013


On 05/28/2013 10:00 AM, Νίκος Γκρ33κ wrote:
> I do not know here to find connections.py Michael.

It's part of the pymysql package that you installed.  Look in there (the
traceback even shows you where the file is).  But you actually don't
even need to look at it on your server.  You can see the source code for
it here:

https://github.com/petehunt/PyMySQL/tree/master/pymysql

> But i do not understand since iam suing the following 2 statements,
> why a unicode error remains.

The traceback told you why the error is happening.  inside the pymysql
library, there is a call to .encode(charset) on your query string.  And
the default charset is latin-1.  You've got to work out a way to change
that and I've already told you exactly how to find out what you need to
do.

> #needed line, script does *not* work without it sys.stdout =
> os.fdopen(1, 'w', encoding='utf-8')
> 
> # connect to database con = pymysql.connect( db = 'pelatologio', host
> = 'localhost', user = 'myself', passwd = 'mypass', init_command='SET
> NAMES UTF8' ) cur = con.cursor()

HINT: this line ^^^^^^ is what you have to modify by passing in a
particular keyword argument that sets the character set (no it's not the
init_command one).  You will have to look at connections.py's __init__
declaration and you should see what you need to pass in.

Yes I could have saved myself a lot of time and typing by giving you the
answer, but that isn't going to help you.  On the other hand, if you
want the easy way out, paypal some money to me and I'll just give you
the answer instead of trying to give you the tools you need to debug
this issue.  The answers are all in the source code to pymysql, which is
open source so you can always read (either on your own server file
system or on the git repository).

> 
> Shall i chnage the connector form 'pymysql' => 'MySQLdb' ?

No.




More information about the Python-list mailing list