Connection to MySql server fails - Python
Question: I'm trying to connect to mySql database using Python. The database is situated
on free webhosting server webzdarma.cz.

I use `mysql.connector.connect` and all of my arguments are correct in my
opinion. The information about connecting to the database are:

    
    
    This information is for PHP but I suppose it should work with Python:
    Server: mysql.webzdarma.cz
    Username: flat
    Database: flat
    Password: xxxx  
    

This is my code:

    
    
    # -*- coding: utf-8 -*-
        import mysql.connector
    
        cnx = mysql.connector.connect(user='flat', password='xxxx',
                                      host='mysql.webzdarma.cz',
                                      database='flat')
    

When try to run this code the error occure:

    
    
        Traceback (most recent call last):
      File "C:/Users/Python/PycharmProjects/Flat/Flat.py", line 6, in <module>
        database='flat')
      File "C:\Python27\lib\site-packages\mysql\connector\__init__.py", line 159, in connect
        return MySQLConnection(*args, **kwargs)
      File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 129, in __init__
        self.connect(**kwargs)
      File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 454, in connect
        self._open_connection()
      File "C:\Python27\lib\site-packages\mysql\connector\connection.py", line 417, in _open_connection
        self._socket.open_connection()
      File "C:\Python27\lib\site-packages\mysql\connector\network.py", line 470, in open_connection
        errno=2003, values=(self.get_address(), _strioerror(err)))
      File "C:\Python27\lib\site-packages\mysql\connector\errors.py", line 181, in __init__
        self.msg = self.msg % values
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xf8 in position 15: ordinal not in range(128)
    

This error is raised because program recieved message in czech language about
failed connection. Do anybody know what am I doing wrong?


Answer: 
    import MySQLdb 
    db = MySQLdb.connect(host="mysql.webzdarma.cz", 
                     user="flat", 
                     passwd="xxxx", 
                     db="flat")
    cur = db.cursor()
    cur.execute("SELECT * FROM YOUR_TABLE_NAME")
    res = cur.fetchall()
    

Try this it will work for sure.

for more details follow question asked [How do I connect to a MySQL Database
in Python?](http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-
mysql-database-in-python)

