Showing posts with label Django. Show all posts
Showing posts with label Django. Show all posts

Wednesday, September 14, 2011

Solve the UnicodeError: ASCII Decoding/Encoding Error in Python

Sometimes we will get the Unicode Error in python, which means you are try to encode or decode a string which is not encoded in ASCII. ASCII is python default encoding, and what we need to do is just overwriting it to utf-8.
Put following codes in sitecustomize.py and put this file in your PYTHONPATH, which means it can be imported. This file may already exists somewhere in your PYTHONPATH, if so, just append the following codes in it. The file sitecustomize.py is a special file which is automatically imported when python restarts.
# sitecustomize.py
# this file can be anywhere in your Python path
import sys
sys.setdefaultencoding('utf-8')

Sunday, August 28, 2011

Install Django+Mod_Python on Ubuntu 10.04

Install general dev tools
sudo apt-get install build-essential devscripts flex 
where flex is essential to compile mod_python.
Install Apache
sudo apt-get install apache2 apache2-threaded-dev
where apache2-threaded-dev is used to compile mod_python.
Install MySQL
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
where libmysqlclient-dev is used to install Python MySQL library. During the installation, you will be asked to set a password for root.
Install Python 2.6
sudo apt-get install python2.6 python2.6-doc python2.6-dev python-setuptools
where python2.6 maybe omitted if it already installed (It's installed with Ubuntu 10.04). After installed python-setuptools, you will be able to install python modules with easy_install.
Install mod_python
svn co https://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk/
cd trunk
./configure --with-python=/usr/bin/python2.6
make
sudo make install
If ./configure fails, check if you missed anything above. To enable the mod_python in apache2, add following to /etc/apache2/httpd.conf
LoadModule python_module /usr/lib/apache2/modules/mod_python.so
Install memcached
sudo apt-get install memcached