including error code and error number when database connection creation fails

pull/4420/head
Kenny Gryp 2015-11-03 16:44:00 +01:00 committed by Matt Clay
parent 85f2165273
commit 4e401fc4e6
1 changed files with 2 additions and 1 deletions

View File

@ -334,7 +334,8 @@ def main():
else: else:
db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], user=login_user, passwd=login_password) db_connection = MySQLdb.connect(host=module.params["login_host"], port=module.params["login_port"], user=login_user, passwd=login_password)
except Exception, e: except Exception, e:
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials") errno, errstr = e.args
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials (%s: %s)" % (errno, errstr) )
try: try:
cursor = db_connection.cursor(cursorclass=MySQLdb.cursors.DictCursor) cursor = db_connection.cursor(cursorclass=MySQLdb.cursors.DictCursor)
except Exception, e: except Exception, e: