Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MySQL hardcoding?

Reply
Thread Tools

MySQL hardcoding?

 
 
marexposed@googlemail.com
Guest
Posts: n/a
 
      04-17-2008
I've got this error (see the path in last line)

db=MySQLdb.connect(host='localhost',use_unicode = True, charset = "Windows-1251",user='root',passwd='12',db='articulos')
File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 74, in Connect
return Connection(*args, **kwargs)
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 198, in __init__
self.set_character_set(charset)
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 277, in set_character_set
super(Connection, self).set_character_set(charset)
OperationalError: (2019, "Can't initialize character set Windows-1251 (path: C:\\mysql\\\\share\\charsets\\)")

The truth of the matter is, MySQL is not installed in that path, but into Program Files.
I don't know where the hardcoding is, but it is certainly somewhere. Except MySQL is reporting a wrong installation path.
I haven't found any other topic in the list about this problem.

I'm using Python 2.4 and latest MySQLdb. Have anyone heard of this issue and how to fix it?

Thanks a lot.
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      04-17-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I've got this error (see the path in last line)
>
> db=MySQLdb.connect(host='localhost',use_unicode = True, charset = "Windows-1251",user='root',passwd='12',db='articulos')


Can't help with the answer to your question, but this may stave off yet
another question:

The empirical evidence from other recent postings is that you are
mucking about with Spanish-language newspaper "articulos" on the web ...
so why charset = "Windows-1251", which is Cyrillic (i.e. Russian etc)??
Perhaps you mean 1252 which is Microsoft's latin1 with extras.

HTH,
John
 
Reply With Quote
 
 
 
 
marexposed@googlemail.com
Guest
Posts: n/a
 
      04-18-2008
On Thu, 17 Apr 2008 22:00:21 GMT
John Machin <(E-Mail Removed)> wrote:

> The empirical evidence from other recent postings is that you are
> mucking about with Spanish-language newspaper "articulos" on the web ...
> so why charset = "Windows-1251", which is Cyrillic (i.e. Russian etc)??
> Perhaps you mean 1252 which is Microsoft's latin1 with extras.
>
> HTH,
> John
> --
> http://mail.python.org/mailman/listinfo/python-list

Yes John, thanks. The only problem is MySQL doesn't include a cp1252 or Windows-1252 or ansi. I'm trying to find my way with different approaches.
But there is certainly a problem if an application goes to the wrong folder to get data as MySQL seems to be doing.

Thanks.
 
Reply With Quote
 
John Nagle
Guest
Posts: n/a
 
      04-21-2008
(E-Mail Removed) wrote:
> I've got this error (see the path in last line)
>
> db=MySQLdb.connect(host='localhost',use_unicode = True, charset = "Windows-1251",user='root',passwd='12',db='articulos')
> File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 74, in Connect
> return Connection(*args, **kwargs)
> File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 198, in __init__
> self.set_character_set(charset)
> File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 277, in set_character_set
> super(Connection, self).set_character_set(charset)
> OperationalError: (2019, "Can't initialize character set Windows-1251 (path: C:\\mysql\\\\share\\charsets\\)")
>
> The truth of the matter is, MySQL is not installed in that path, but into Program Files.
> I don't know where the hardcoding is, but it is certainly somewhere. Except MySQL is reporting a wrong installation path.
> I haven't found any other topic in the list about this problem.
>
> I'm using Python 2.4 and latest MySQLdb. Have anyone heard of this issue and how to fix it?
>
> Thanks a lot.


Well, for one thing, MySQL doesn't have a character set called
"Windows-1251", which is an obsolete Cyrillic variant of Windows.
See the list of MySQL character sets at:

"http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html"

MySQL does have "cp1251", which is apparently the same thing.

Be aware that in Python, there are really only two character
sets - ASCII and Unicode. The "upper code page" thing is deprecated,
and you can't do some string operations on characters with values > 128.
It's best to convert input to Unicode, run everything in Python in
Unicode, send to the database in "utf8", and store your data in "utf8".

You have "use_unicode" set to True. If you're going to run
the MySQL connection in Unicode, you should use "utf8" talking to the
database, and Unicode strings in Python. Otherwise, you have to
understand very clearly exactly how both Python and MySQL handle
character sets, and how this changes in Python 2.4, 2.5, and 3.x.

John Nagle
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to insert PDF file in to MySql and read it from MySql toJAVA App Jeffrey H. Coffield Java 1 07-24-2009 12:29 AM
MySQL-python-1.2.2 install with no mysql washakie Python 4 01-15-2008 08:15 PM
"mysql.h: No such file or directory" when building MySQL-python francescomoi@europe.com Python 2 05-11-2005 03:12 PM
DBD:mysql doesn't read mysql option file /etc/my.cnf file JL Perl 0 01-28-2005 03:19 AM
"Pure Python" MySQL module like Net::MySQL Ravi Python 6 07-21-2003 06:53 PM



Advertisments