Python Query database Data nonetype error

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.