When you debug a MySQL database in Python, there is no problem when testing a single query statement.
The execution process is as follows:
1, by the connection object Conn gets to a cursor. cur = conn.cursor ()
2. Execute the SQL statement. Count = Cur.execute (SQL)
3, read the data. result = Cur.fetchone () #获取一条
4, close the cursor, connect. Cur.close () Conn.close ()
This query process executes once without problems, but it occurs when multiple executions occur, Nonetype.
or CharSet = Db.character_set_name ()
_mysql_exceptions. Interfaceerror: (0, ")
and other errors.
The reason is that the defined Conn Connection object is a global variable, and when the first execution is completed, the query is finally changed,
Performs a conn.close () close operation that causes the Conn connection object to close. When you use a Change object again,
The error shown in title appears.
Python Query database Data nonetype error