- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
使用以下方法访问我的网络应用程序后:
- Python 2.7
- Bottle 微框架 v. 0.10.6
- Apache 2.2.22
- mod_wsgi
- 在 Ubuntu 服务器 12.04 64 位上;几个小时后我收到此错误:
OperationalError: (2006, 'MySQL server has gone away')
我正在使用 MySQL - Python 中包含的 native 版本。它通常发生在我不访问服务器时。我已经尝试使用以下方法关闭所有连接:
cursor.close()
db.close()
其中 db 是标准的 MySQLdb.Connection() 调用。
my.cnf 文件看起来像这样:
key_buffer = 16M
max_allowed_packet = 128M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
这是默认的配置文件,除了 max_allowed_packet 是 128M 而不是 16M。
对数据库的查询非常简单,最多检索大约 100 条记录。
谁能帮我解决这个问题?我确实有一个想法是使用 try/except,但我不确定这是否真的有效。
提前致谢
杰米
更新:try/except 调用无效。
最佳答案
这是 MySQL 的错误,不是 Python 的。
此处列出了可能的原因和可能的解决方案:MySQL 5.5 Reference Manual: C.5.2.9. MySQL server has gone away .
可能的原因包括:
- You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
- A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
- You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).
- You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's
max_allowed_packet
variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section C.5.2.10, “Packet too large”.- You also get a lost connection if you are sending a packet 16MB or larger if your client is older than 4.0.8 and your server is 4.0.8 and above, or the other way around.
- and so on...
换句话说,有很多可能的原因。浏览该列表并检查所有可能的原因。
关于python - 错误 2006 : "MySQL server has gone away" using Python, Bottle Microframework 和 Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12444272/
我正在开发一个基于 Python 的应用程序(HTTP -- REST 或 jsonrpc 接口(interface)),它将用于生产自动化测试环境。这将连接到运行所有测试脚本的 Java 客户端。即
我正在关注Recipes的bottle框架。 当我尝试下面的代码时 #filename: mywebapp.py from bottle import Bottle, run, request app
我通常使用method version处理 Bottle 中的路由 bottle.route("/charge", "GET", self.charge) bottle 文档严重依赖 @route 装
如何在 Bottle 框架中执行基本身份验证?在 flask 中我曾经: def check( username, password ): # This function is called
是否可以在同一应用程序(同一端口)中托管一个普通 Bottle 应用程序和一个 WebSocket 应用程序(例如: https://github.com/defnull/bottle/blob/ma
我有使用 python 2.7.2、bottle 0.10.9 和“瑞士军刀” scrapy 0.14.1 编写的简单 REST API。 简单来说,只有一种方法 (myserver:8081/dop
嗨,有没有办法优雅地关闭 Bottle 服务器。在某种程度上,它应该能够在最终停止之前执行几个步骤。这对于线程和数据库状态等的一些清理至关重要,以避免重新启动期间的损坏状态。 我正在使用 mod ws
我正在尝试让服务器发送事件在Python中工作,所以我找到了一些演示代码,令我惊讶的是,它只部分工作,我不明白为什么。我从here获取代码并进行了一些小的更改,这样我就可以看到什么在起作用(我包括了一
有没有办法让我的网站可以通过我所连接的网络访问? from bottle import route, run, template @route('/hello/') def index(name):
如果我直接从 Bottle 导入 post、get 和 jinja2_view,我就可以使用 jinja2_view 作为装饰器: from bottle import get, post, requ
我正在尝试将 Bottle.py 作为脚本内的进程运行,但我很沮丧,因为它没有按我的预期工作。这是我的脚本的假设/简化表示。我尝试添加尽可能多的评论。 magball.py import serial
(免责声明:我正在发现 python) 使用以下代码: @route('/test', method='POST') def index_view(): image = request.fil
我有一个 Bottle 服务器在端口 8080 上运行,使用“gevent”服务器。我使用这个服务器来支持一些简单的“服务器发送事件”。 我的问题可能与不知道我的设置是如何工作有关。我希望有人能花时间
我最近接触了 Bottlepy,这几乎是我第一次使用模板引擎。(之前我会简单地用传统 PHP 制作我需要的东西) 我的问题是这样的,假设我有一个基本布局(一个简单的 HTML/CSS 布局),并且,例
我如何管理 Bottle 中的多个应用程序,一次运行? 应用 0 from bottle import Bottle app0 = Bottle() @app0.route('/app0/') def
我将 bottle 用于一个显示日历并允许用户指定年份和月份的简单应用。定义了以下路由: '/' # 当前年份和当前月份 '/year' #年和当月 '/year/month' #年月 但是,无法识别
我正在使用 Bottle 框架。我已经设置了 @error 装饰器,所以我能够显示我自定义的错误页面,如果发生任何 500 错误我也可以发送电子邮件,但我需要在电子邮件中发送完整的回溯。有谁知道如何将
我有这样的目录结构: . ├── controller │ ├── FooController.py │ ├── __init__.py │ ├── main.py FooController
我在 bottle 中使用 html,在“index.html”中我导入外部 JS 和 CSS。 但是加载页面时,找不到css和js。 我的项目结构: testBottle.py 中的代码: impo
嗨,我是 python 和 bottle 的新手 我有一个网站 这是结构 |root index.py |classes session.py 如何从 index.py 访问
我是一名优秀的程序员,十分优秀!