A Python unicode object is a sequence of Unicode code points and, by definition, native Unicode. The python str string is a sequence of bytes, which can be Unicode characters encoded with a specific encoding (UTF-8, Latin-1, Big5, ...).
First question: if source is a unicode object or str string. This source.encode("utf-8") works just means that you can convert source to a UTF-8 encoded string, but do you do this before passing it to the database functions? It seems that the database expects the inputs to be encoded using UTF-8 and complains that the equivalent source.decode("utf-8") .
If source is a unicode object, it must be encoded in UTF-8 before passing it to the database:
source = u'abc' call_db(source.encode('utf-8'))
If source is str encoded as something other than Utf-8, you must decode this encoding and then encode the resulting Unicode object to UTF-8:
source = 'abc' call_db(source.decode('Big5').encode('utf-8'))
sth
source share