|
Erdi Balint
erdibalint at freemail.hu
Mon Oct 10 16:00:24 EDT 2005
Hi Nicolas,
Thanks for your help, I've added one line to your script to see if the
interpreter uses 2 or 4-byte wide unicode strings (the root of the problem).
the script:
import sys
def handler(req):
req.content_type = 'text/plain'
req.write(sys.version+'\n')
req.write(sys.exec_prefix+'\n')
req.write(`sys.maxunicode`+'\n')
return apache.OK
the output:
2.3.4 (#1, Dec 30 2004, 12:39:04)
[GCC 3.3.5 (Debian 1:3.3.5-5)]
/usr
65535
So there it is, black & white, it uses 2-byte wide Unicode chars, that
causes the trouble, but how do I track down which python interpreter is
called? To my knowledge, python >=2.3 uses 4-byte wide unicode, so how
do I track down which python interpreter is used? (or maybe more simple
question is how do I force the mod_python/mysqldb extension to use the
"good" python interpreter)?
Balint
Nicolas Lehuen wrote:
> Are you sure mod_python is using the same Python interpreter as the one
> you made the test in ?
>
> Try running this handler :
>
> from mod_python import apache
> import sys
> def handler(req):
> req.content_type = 'text/plain'
> req.write(sys.version+'\n')
> req.write(sys.exec_prefix+'\n')
> return apache.OK
>
> Regards,
> Nicolas
>
> 2005/10/9, Erdi Balint <erdibalint at freemail.hu
> <mailto:erdibalint at freemail.hu>>:
>
> Thank you, Nicolas, that fixed that problem, but now I have another one,
> when importing a module from the MySQLdb module, I get the following
> exception:
>
> File "/var/www/trivia/control/trivia.py", line 5, in _connect
> db = MySQLdb.connect(user="xxx",passwd="xxx",db="xxx")
>
> File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 66,
> in Connect
> return Connection(*args, **kwargs)
>
> File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> 117, in __init__
> from converters import conversions
>
> File "/usr/lib/python2.3/site-packages/MySQLdb/converters.py", line
> 40, in ?
> import array
>
> ImportError: /usr/lib/python2.3/lib-dynload/array.so: undefined symbol:
> PyUnicodeUCS4_FromUnicode
>
> I've come across a python faq item, that says the following about the
> cause of the error:
>
> "...
> If instead the name of the undefined symbol starts with PyUnicodeUCS4,
> the problem is the reverse: Python was built using 2-byte Unicode
> characters, and the extension module was compiled using a Python with
> 4-byte Unicode characters.
> ...
>
> You can check the size of the Unicode character a Python interpreter is
> using by checking the value of sys.maxunicode:
>
> >>> import sys
> >>> if sys.maxunicode > 65535:
> ... print 'UCS4 build'
> ... else:
> ... print 'UCS2 build'
>
> "
> Ok, so in theory, my Python interpreter uses 2-byte Unicode characters,
> but I've checked it (I am python 2.3.5) with the above code snipplet,
> and it is not so, I am using 4-byte Unicode characters? Then why is the
> error?
>
> Thank you for your help,
> Balint
|