每当我测试我的网站时,它都会随机崩溃并显示以下错误:mysql_exceptions.OperationalError: (2006, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")唯一的解决办法是重新启动程序。代码提取:######################################################Initialize databasedb = MySQLdb.connect(host="<Name removed>.mysql.pythonanywhere-services.com", user="<Name removed>", passwd="<Password removed>", connect_timeout=3600, db="<Name removed>$main")cur = db.cursor()@app.route('/form', methods = ['GET', 'POST'])def form(): if request.method == 'POST': #Import data from the form name = request.form['name'] first_name = request.form['first_name'] last_name = request.form['last_name'] email = request.form['email'] password = request.form['password'] country = request.form['country'] account_type = 'admin' #Encrypt the password password = sha256_crypt.encrypt(password) #Generate the country code based off of the input loop = cur.execute("SELECT * FROM table;") cur.execute("SELECT code, list FROM table;") row = cur.fetchone()追溯:2018-12-10 14:07:24,036: Exception on /form [POST] Traceback (most recent call last): File "/home/<Link removed for posting>/.virtualenvs/my-virtualenv/lib/python3.4/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/home/<Link removed for posting>/.virtualenvs/my-virtualenv/lib/python3.4/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/<Link removed for posting>/.virtualenvs/my-virtualenv/lib/python3.4/site-packages/flask/app.py", line 1718, in handle_user_exception错误发生在重新加载网站的前 5 分钟内,有时会在重新加载时立即发生。寻找允许 MySQL 永不超时的解决方案或允许永远不会发生此错误的解决方案。
1 回答
慕的地10843
TA贡献1785条经验 获得超8个赞
空闲时间超过数据库服务器上的连接超时设置的连接将被关闭;当您下次尝试使用关闭的连接时,您会收到该错误消息。PythonAnywhere 上的超时为 300 秒。
有一个PythonAnywhere 帮助页面,其中包含有关如何管理 MySQL 连接的一些提示和技巧,以免造成问题,因此这可能是寻找解决方案的好地方。
添加回答
举报
0/150
提交
取消