You are not logged in.
Pages: 1
Ok, since i dont like php that much and wanted to write a webbpage i thought python whould be a good choice. I run lighttpd with python through fcgi. It works fine except when i want to put a string containing "åäö" (swedeish chars) in mysql.
i get this errormsg:
http://www.ds.hj.se/~major/fel.html
The thing is that when i use mysql-cmd i can use åäö like theres no tomorrow, and python/lighttpd can display then properly on the page.
I know it has to do with charsets and such but i dont know where to change it. Has anyone else had this problem? How to solve?
Offline
query = "insert into cp values('bajs', 'xe5xe4xf6')", query.encode = <built>, charset = 'latin1'
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 31: ordinal not in range(128)
change charset='latin1' to charset='utf8'. At least I think it is utf8 it may be some other string, but that's what you need to change.
Offline
ok. tried modifying the lib-source. No dice.
The script works fine on another server i might add. But as far as i can tell the only difference is the mysqld-version. I have 5.0.22 and the other server use 4.0.24.
I think that the problem is with mysql, but i cant seem to find any info on how to get it to work
Offline
what is the char encoding set to on the actual mysql table?
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
mysql> SHOW FULL COLUMNS FROM cp;
+-------+--------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+--------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| user | varchar(255) | latin1_general_ci | YES | | NULL | | select,insert,update,references | |
| msg | text | latin1_general_ci | YES | | NULL | | select,insert,update,references | |
+-------+--------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
2 rows in set (0.00 sec)
looks like latin1 to me...
Offline
ALTER TABLE tbl_name
[[DEFAULT] CHARACTER SET charset_name] [COLLATE collation_name]
you might try altering the character set on that table..
Not sure what character set you would want to use though..maybe latin1_swedish_ci. That is one of the common ones I see..seems fairly compatible.
ALTER TABLE cp CHARACTER SET latin1_swedish_ci COLLATE latin1_swedish_ci;
http://dev.mysql.com/doc/refman/5.0/en/ … yntax.html
Not sure if you need to change the column char sets themselves...
but who knows.. we could be barkup up the wrong tree..but I think we are on the right track.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
> since i dont like php that much and wanted to write a webbpage i thought python whould be a good choice.
try this,
http://www.conflux.ee/
I removed my sig, cause i select the flag, the flag often the target of enemy.
SAR brain-tumor
[img]http://img91.imageshack.us/img91/460/cellphonethumb0ff.jpg[/img]
Offline
> since i dont like php that much and wanted to write a webbpage i thought python whould be a good choice.
try this,
http://www.conflux.ee/
How does that aid him in actually writing a site?
Offline
cactus:
No dice.
and, the conflux-thingie... not even sure wtf it is.. but it wont help me in any way. that im sure about.
Offline
The problem isn't the Latin1 encoding (Latin1 should work fine for Swedish) it's that your MySQLdb Python extension is trying to encode your SQL not as Latin1 but as ASCII (which means no chars beyond 0x7F).
I haven't tried to deal with this myself, but there is a bunch of possibly related discussion here
Offline
Yeah, that its trying to use "ASCII" ive figured out.
>>> import MySQLdb
>>> db=MySQLdb.connect(host='localhost', user='major', passwd='**********', db='bajs', use_unicode=True)
>>> db.character_set_name()
'latin1'
>>>
So.... it should use latin1, right?
Offline
Pages: 1