Python连接MySQL报错

问题遇到的现象和发生背景

现在编写的是一个SQLserver与MySQL的连接工具,当代码执行发生报错的时候就停止了代码,重新运行后需要再次输入对应的参数,请问怎么样才能让代码报错的时候不退出代码,继续提示输入需要执行的操作呢

问题相关代码,请勿粘贴截图

# -- encoding:utf-8 --
import pymysql
import pymssql


def SQLServer():
    pymssql.connect()


def MySQL():
    try:
        host_input = input('请输入主机名')
        user_input = input('请输入用户名')
        pswd_input = input('请输入密码')
        dbs_input = input('选择连接的数据库')
        conn = pymysql.connect(host=host_input, user=user_input, password=pswd_input, database=dbs_input)
        cur = conn.cursor()
        while True:
            sql = input('连接成功,输入需要执行的操作')
            return_sql = cur.execute(sql)
            print('影响的行数', return_sql)

    except Exception as e:
        print(e)


if __name__ == '__main__':
    choice = input('请选择连接的数据库类型:1.SQLserver  2.MySQL')

    if choice == '2':
        MySQL()
    elif choice == '1':
        SQLServer()
    else:
        print('请输入正确的方法')
运行结果及报错内容

img

img

我想要达到的结果

在报错的时候不中止执行代码,继续执行while True部分的代码

根据报错可以指定,mysql版本不对,版本和数据库版本对应起来,在测试。