UnicodeDecodeError - encoding in Python
Question: I'm trying to connect to a database on a web hotel. However, I get this error:

    
    
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xf8 in position 24: ordinal not in range(128)
    

The error is on the same line as the hostname and database name. I'd rather
not give away the password and hostname... all I can say is that the strings
do not contain any special characters. I have

    
    
    reload(sys)
    sys.getdefaultencoding('UTF-8')
    

on the top, but after I run the program I get the same error. Hope someone can
help me on this!

UPDATE:

    
    
    ! -*- coding: utf-8 -*-
    import MySQLdb, cgi, cgitb
    import mysql.connector
    import sys
    reload(sys)
    sys.getdefaultencoding()
    
    class mySQL_handling():
    def __init__(self):
        self.conn = mysql.connector.connect(user = <string>, passwd = <string>,
            host = <string>, database = <string>, port = 22)     
    
    def test(self):
        print "top kek"
    
    
    def run(self):
        while True:
            self.test()
    
    
    if __name__ == "__main__":
        pgi = mySQL_handling()
        pgi.run()
    

Really sorry for not being able to give away the strings...


Answer: Usually if the database admits unicode strings its because of 2 reasons, you
havent configured your file settings to utf-8 and/or you havent set up the
encoding in the python shebang

    
    
    # -*- coding: utf-8 -*-

if you have the file setup like this you better don't declare the unicode
strings with a u'' because its supossed for all of them to be unicode.

