Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python MySQLdb exceptions

Just starting to get to grips with python and MySQLdb and was wondering

  1. Where is the best play to put a try/catch block for the connection to MySQL. At the MySQLdb.connect point? Also should there be one when ever i query?

  2. What exceptions should i be catching on any of these blocks?

thanks for any help

Cheers Mark

like image 325
Mark Lakewood Avatar asked Jul 13 '09 05:07

Mark Lakewood


People also ask

Does MySQLdb support Python 3?

MySQLdb module, a popular interface with MySQL is not compatible with Python 3.

How are errors returned when a query or connection fails in MySQLdb?

InterfaceError: When database connection fails for some reason, MySQLdb will raise an InterfaceError. Note InterfaceError only get raise when there is internal problem in connection to the database, MySQLdb will not raise InterfaceError because of wrong database name or password.

What is Python MySQLdb package?

MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API. Packages to Install. mysql-connector-python mysql-python.


1 Answers

Catch the MySQLdb.Error, while connecting and while executing query

like image 135
Anurag Uniyal Avatar answered Oct 22 '22 19:10

Anurag Uniyal