You are not logged in.

#1 2006-07-26 18:02:48

major
Member
From: Ockelbo, Sweden
Registered: 2005-12-30
Posts: 25

python through fcgi

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

#2 2006-07-26 19:14:00

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: python through fcgi

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

#3 2006-07-26 20:32:41

major
Member
From: Ockelbo, Sweden
Registered: 2005-12-30
Posts: 25

Re: python through fcgi

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 sad

Offline

#4 2006-07-26 20:55:14

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: python through fcgi

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

#5 2006-07-26 21:06:06

major
Member
From: Ockelbo, Sweden
Registered: 2005-12-30
Posts: 25

Re: python through fcgi

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

#6 2006-07-26 22:05:03

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: python through fcgi

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

#7 2006-07-26 22:23:58

user
Member
Registered: 2006-03-29
Posts: 465

Re: python through fcgi

> 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

#8 2006-07-27 09:35:50

postlogic
Member
Registered: 2005-02-24
Posts: 410
Website

Re: python through fcgi

user wrote:

> 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

#9 2006-07-27 10:02:31

major
Member
From: Ockelbo, Sweden
Registered: 2005-12-30
Posts: 25

Re: python through fcgi

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

#10 2006-07-27 14:11:30

Kopsis
Member
Registered: 2006-01-31
Posts: 15

Re: python through fcgi

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

#11 2006-07-27 16:34:32

major
Member
From: Ockelbo, Sweden
Registered: 2005-12-30
Posts: 25

Re: python through fcgi

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

Board footer

Powered by FluxBB